Phalcon Framework Usage Guide _php instance

Source: Internet
Author: User
Tags log log

The first time I knew Phalcon was just learning PHP, and recently I finally had a chance to use it. So talk about some of the feelings

The individual is very fond of phalcon this framework of the way, using dependency injection, so that the code organization is very flexible, coupled is very low. But, perhaps, the frame thing is too much to encounter several pits. GitHub more than a year of issue has not been resolved. But if you have some experience in development, you can fix it yourself. I've wasted a lot of time in these pits.

The first one is view.

  Phalcon view, can be divided into two parts, one is the global layout, the second is the controller/action part, so that the
  use of more convenient, set a good layout, only concerned about the controller part of the view can be.
  However, regarding the path setting problem of view, we should pay attention to these several parameters

Mainview (main layout file path + filename, but does not include extension, extension is the key value when injecting the view engine),

Layoutsdir (layouts directory path),

Layout (the main Layout filename, depending on the requirements, dynamically use a file in the Layouts directory to act as a mainview),

Partialsdir (when using the partial function, look for a template file, such as partial (' Main/header ') to find the path is "/Your Partialsdir/main/header.volt".),

Viewsdir (sets the directory where the corresponding template files for controller/action are located. Similar to Partialdir, automatically find the template files under the directory)

BasePath (the base directory of the view's directory, Phalcon and the path based on all the settings dir, find the template file, the pit is this)

When I first started using this view, I used an absolute path because it was easy to configure and manage absolute paths.
Then I got caught in the pit. Wasted an afternoon of time debugging.
Repeated tests based on the examples given in the official document show that the view component can only use relative paths to set the path, BasePath without setting.

In a rage to go over the source code of Phalcon. The development language is the language developed by the Zephir,phalcon team.

Language grammar is simpler and easier to understand. And then I saw the sentence.

..]

It looks as if there is no judgment, relative path or absolute path, that is directly combined, and guess that this is causing the problem.

and is to parse the action directly in order, layout, main layout these template files.

So I wanted to verify it. So I wrote a few debug files, I intend to debug.

Search Phalcon source Process omitted 1000 words ... Find the inevitable will call, and have the path to deal with several main methods, inherit view related to several class

Here also stressed that a lot of people like to use Echo, the general situation is no problem,
but it is best to use file records, because the echo limitation is very large,
you do not know when echo buff open, when closed. Using files to log log is most insured.

I tested the code using multiple modules in the way.

Baseview file, Inherits Phalcon view, and opens the error message for this method

Basevolt files, inheriting template engine volt

View injection code, and directory structure as shown

Log logs are as follows

The page output is as follows:

As you can imagine, using absolute paths, at any rate, Phalcon are directly stitching the path above set,

When developers want to dynamically use Controller/action view, but layouts home directory again in the upper directory, there will be problems.

Phalcon find the main layout path isPhalcon\Mvc\View\Exception: View '/Users/Hin/work/phalcon_mode/app/modules/admin/views/layouts/main' was not found in the views directory

And what I'm asking for is/Users/Hin/work/phalcon_mode/app/views/layouts/main

Then the path is not found and the main layout template file does not work ....

所以,真的就只是直接组合三个路径而已..所以,在设置路径的时候,就看自己的取舍了.

Phalcon View source Three variables, Basepath,viewdir (the key is the author of Viewdir this variable to understand the error, resulting in bugs) as the basis of the path. Viewpath is the Action view,layout view, which is the path to main view, when _enginrender is executed sequentially.
Understand this, you can slowly set the path of ...

There are three solutions.

One is to write a view of their own to inherit Phalcon view, processing path. The idea is that in addition to the action positioning, other positioning will viewdir into empty.
The second is to modify the Phalcon source code, and then compile it yourself (in the _enginrender external processing good path positioning, removal of _enginrender and path positioning coupling)
Three is, regardless of, directly using the relative path (do not set the BasePath, Viewsdir because you want to dynamically position action view, use absolute path, Layoutsdir Partialsdir use relative path)

GitHub is someone has sent this bug issue, but the author ignored ...

------------------------------Gorgeous split Line------------------------------------

The second model

There is a pit, is about Phalcon model. The same is the issue, the author is not tube.
The Setter link Description method is provided according to the document model, but in practice the setter does not work ...

然后像view一样,自己修复好...

Personally think setter getter is very useful function, but some people feel useless, opinions.
Our development mode is model and controller by different people to develop, with setter getter, data caller just take the data can be,
model data problems, in the model can be modified, Controller does not need to be changed. Coupling on working mode can be reduced a lot.

However, the development of this framework of the project aborted, and then the depth of the pit can not be met. No surprises, not in the short term.
I've had a bad mood lately. Write more casually. Be a good record ...

Finally directly attached GitHub source code, multi-module pattern development with such a directory structure is also good, hoping to help others

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.