user1547410
user1547410

Reputation: 893

Phalcon how are views linked to controllers

I created a scaffold crud for my database table app_categories

This creates a model and controller called

AppCategories

But the views are created in a folder called

app_categories

Previously i had assumed that the way views are linked to controllers are by the name but this is clearly different.

So i have 2 questions:

1 - Is it simply that it strips out the _ and it is linked via the name or is there another way that views and controllers/models are linked?

2 - Lets say i wanted to move everything into a new folder so instead of views/app_categories i wanted to move it to views/admin/app_categories/ what would i need to change to make it work, i guess thats related to 1 and it might be a silly question but since i cant seem to find out how it links models to views i dont really know. In Yii you render the view and give the link of where the view is found but its not obvious how it works in Phalcon.

Im new to Phalcon but i have tried scanning the ebook "getting started with phalcon" and also the documentation and a video tutorial i bought on phalcon but im struggling to find it, i might be looking in the wrong part or it might not be covered, more likely its very obvious and i missed it.

Upvotes: 0

Views: 303

Answers (2)

rzx10r
rzx10r

Reputation: 134

You should need learn the structure since has many types for download. https://github.com/phalcon/mvc

AppCategories is camelized so the views folder goes to app_categories for router goes to /app-categories

Appcategories -> view = appcategories -> router = /appcategories

About the folder structure you should try multiple modules /admin/views /frontend/views

https://github.com/phalcon/mvc/tree/master/multiple

Upvotes: 0

David Duncan
David Duncan

Reputation: 1858

1)

If a view is not manually picked then phalcon will automatically resolve the view based on the controller/action

e.g.

route /app-categories

resolves to

AppCategoriesController
indexAction

and resolves the view

views/app_categories/index.(phtml/volt)

The model has nothing to do with how any of this is resolved, it is handled inside of the router

Source: http://docs.phalconphp.com/en/latest/reference/routing.html#default-behavior

2) If you read further in that link you can customize how the router will handle your urls. What you are looking for is module routing: http://docs.phalconphp.com/en/latest/reference/routing.html#routing-to-modules

You will need to setup a module skeleton for that to work however.

The easiest answer to your question though is to just manually pick the view

$this->view->pick('/admin/app_categories/index');

I would recommend setting up modules for what you are interested in doing

Upvotes: 1

Related Questions