Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yaf routing with namespace is on option #577

Open
i-luka opened this issue Jul 18, 2022 · 4 comments
Open

yaf routing with namespace is on option #577

i-luka opened this issue Jul 18, 2022 · 4 comments

Comments

@i-luka
Copy link

i-luka commented Jul 18, 2022

I have a yaf project in the docker. I setup php with
`RUN mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini

RUN echo 'extension=yaf.so' >> $PHP_INI_DIR/php.ini

RUN echo 'yaf.use_spl_autoload = 1' >> $PHP_INI_DIR/php.ini

RUN echo 'yaf.use_namespace = 1' >> $PHP_INI_DIR/php.ini

RUN echo 'yaf.name_suffix = 1' >> $PHP_INI_DIR/php.ini

RUN echo 'yaf.name_separator = ' >> $PHP_INI_DIR/php.ini

RUN echo 'yaf.library = /library' >> $PHP_INI_DIR/php.ini`

Then I made template with yaf_cg with --namespaced option.
But I had an error of class not fount for ErrorController and actualy for default controller IndexController which was made by yaf_cg utility. So, I eventualy, get right code for controller wich look like this
image

I thought it make's me happy but now I can't setup routing in the way it works.

I tried setups like this
`project.type="rewrite"

project.match="/product"

project.route.module=

project.route.controller=Yaf\Index

project.route.action=info`

I tired project.route.controller=Index too, and another too, but I get only default route.

So, why yaf_cg makes wronge template and how really make routing with that namspacing which I have?

@i-luka
Copy link
Author

i-luka commented Jul 18, 2022

project code: https://github.com/i-luka/yaf_project

@Sgenmi
Copy link

Sgenmi commented Sep 9, 2022

@letwang
Copy link

letwang commented Dec 14, 2022

@yunx-lee
Copy link

Yaf application uses the top-level namespace(eg: \).
The namespace of the controllers, models, plugins does not need to be declared.

Your controller class name must include the file name and join suffix 'Controller'.
eg: application/controllers/Index.php
<?php
class IndexController extends \Yaf\Controller_Abstract {
    public function indexAction() {
        // do something
    }
}

When Yaf loads a class file, it will find the corresponding file under the controllers, models or plugins directory based on the class name suffix.
eg 1:
class name: IndexController
suffix:  Controller
directory: application/controllers/Index.php

eg 2:
class name: UserModel
suffix:  Model
directory: application/models/User.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants