laruence / yaf

Fast php framework written in c, built in php extension
http://pecl.php.net/package/yaf
Other
4.52k stars 1.37k forks source link

yaf routing with namespace is on option #577

Closed i-luka closed 4 months ago

i-luka commented 2 years ago

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 commented 2 years ago

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

Sgenmi commented 2 years ago

https://github.com/Sgenmi/eYaf

letwang commented 1 year ago

https://github.com/letwang/HookPHP/

yunx-lee commented 1 year ago
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