What is the best way to create a extension for Yii2?
How to register the extension with the application and how to organize views, controllers and models within the extension?
You can follow each step below to help you set-up your first Yii2 extension:
1. Github setup
Create a new github repo and make sure to follow the naming conventions for yii2-extensions like this:
ourcompany/yii2-ourextension
ourcompany being our github-scope and ourextension the name of our extension.
2. Local project setup
Create a local folder where you will develop the extension. First create a file composer.json. This folder should not be in the vendor-folder of an existing project! It won't work any other way, except to declare a namespaces within autoload.php of surrounding project manually.
composer.json
The most important things to remember:
After that, run composer update this will create the vendor folder containing all referenced libraries.
Here is an example of composer: https://github.com/asinfotrack/yii2-toolbox/blob/master/composer.json
Pay special attention to the autoload block at the end of the file! In this case autoloader that asinfotrack/yii2/toolbox will be mapped to the root-folder of the project. Folder models with class in your project root should have the namespace asinfotrack/yii2/toolbox/models.
.gitignore
The next to create .gitignore-file. Exclude the vendor-folder and all IDE files.
Also an example of the same extension mentioned above. Simply copy/paste it: https://github.com/asinfotrack/yii2-toolbox/blob/master/.gitignore
Git-repo-setup
Now initialize the git-repo, simply navigate to directory and execute the command git init. To add all files and commit for the first time, execute git add -A and git commit -m "message here". Now you are ready to push repo to github.
Need to set the remote of repo to github. This is done with the following command:
git remote add origin https://github.com/ouraccount/ourrepo.git
Also make sure that the following config vars are set correctly:
git config user.email git config user.name
The email should match with your github-account email. If you want to change the values, simply append them to the commands above. Like below:
git config user.email "my-mail@my-domain.com"
Now we need to push the extension to github:
git push origin master
3. Packagist-setup
For other users to be able to reference our extension within their projects, we need to register it with packagist.org.
Create an account and submit extension as explained here: https://packagist.org/packages/submit
4. Connecting packagist and github
Packagist mirrors repo for further distribution. Enabling the Packagist service hook ensures that your package will always be updated instantly when you push to GitHub.
Go to the settings of github-repo and navigate to Webhooks & Services. Then add a new hook for packagist. This is supported natively by github. Find the packagist-hook in the dropdown.
We need to provide packagist-API-Token which we can find on the top of account-page when logged into packagist.org. Everything is documented very well here:
5. Conclusion
That's it! When performing a new commit to github, it will be mirrored automatically to packagist. With a few minutes delay we will receive the updated version of our extension when we execute composer update.
At first all of this might look intimidating and complicated, but actually it's pretty straight forward.
Now days, Freelancing is simplest, easiest and best way to Hire PHP developers for full-time or part-time.
Once you've decided to hire dedicated PHP developer instantly, you need to follow some basic steps to Hire PHP developer for website design & development. The first place to start with is your outsourced project itself, define outline of your website concept with complete requirement and summarizing the vital elements and analyze your requirement for determine the employment type (individual/agency), budget and share your requirement on freelance platform. Within 24 hours you get top PHP developers proposals, you need to scan their portfolio and shortlisted them, preferred only experienced PHP developer because hiring experience person is always better deals. And finally invite them for interview to assess their abilities. If you aren't from a technical background, seek someone proficient to conduct a technical interview of PHP developers.
Hire PHP developer to build a website as per the requirement of your business in a convenient manner.
A team of professionals can undertake the requirement of your business and can turn your ideas into reality.
Hiring PHP experts is a must for you if you want to build a best PHP based site with a professional look. Top Web developers from all over the world are opting for this software to build a site because of its cost effectiveness, flexibility, simplicity and free availability. Top PHP developers for hire to accomplish your business projects.
If you decide to create a website in PHP and you don't know PHP programming and website design. Freelance market is best choice for development of an attractive and fully functional website. You just focus on your business and define the primary purpose of your website, your specific user experience and fundamental goal of your website. Following points are step by step guide for creating a website for business.
PHP (Hypertext Pre-processor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
PHP Programming Languages most commonly used for web site and web Application Development. PHP could be use for a general purpose, server-side scripting language run a web server that is designed to form dynamic pages and applications.
PHP as a web development option is secure, quick and a reliable that gives lots more advantages to form it accessible to a lot of people. It is to be given a thought on what has made PHP Programming as one of the most commonly programming language for the online business.
Common mistake that need to be avoided while hiring a PHP developer