28Feb2016
Basic CLI support
Lately I worked with Laravel for a project. It is a very powerful tool. I liked many things, others are less pleasant. But this is another story.
A thing I really appreciated is the CLI (Command Line Interface). The first time I created a controller with the CLI I decided to add this power to X3 CMS.
As usual with small changes X3 CMS become suitable also for this.
I chose to keep the MVC logic also for the CLI. So to add a new CLI function means to write a new controller and, if it is needed, a new model.
Let's see some examples
The only function we have now is the create function: with this we can create controllers, models and views.
Before to test set write permissions on the folders cms/controllers/area_you_want_to_use, cms/model and cms/views/area_you_want_to_use.
-
$ php x3 create controller public foo
will create a controller for the public area named foo
-
$ php x3 create model public foo
will create a model for the public area named foo
-
$ php x3 create view public foo
will create a view for the public area named foo
Items for the public or private area are very basic, is not possible to foresee what you will need.
If you do the same for the admin area you will have a complete Model+View+Controller with a new table and related permissions for the users in admin group.
-
$ php x3 create controller admin foobar
will create a controller for the admin area named foobar
-
$ php x3 create model admin foobar
will create a model for the admin area named foobar
-
$ php x3 create view admin foobar
will create a view for the admin area named foobar
Now login to refresh your permissions, create a foobar page in the admin area, enable it and put it in the Global menu. Reload the page and the game is finished. If you click on Foobar you will see a page of information and instruction (read it carefully to get useful information).
With your favorite editor open the file cms/controllers/admin/foobar_controller.php and edit the _default() method.
Follow the instructions in the comments to redirect _default() to index() method and reload the page.
Behind the curtain
Who develops web applications knows that the most time-consuming part of a feature is the admin side. A simple page like a FAQ page requires more work in the admin side (CRUD operations, permissions and translations) than in the public (where if you want to spend extra time you can write few lines of Javascript).
X3 CMS with his plugins (like X3Plugin_Builder) solves this problem but sometime we need a simpler solution to add quickly a new page for a small thing.
Now we have it.
Have fun