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 3.2.5 CLI 模式运行参数接收不到呢? #506

Open
hanwuqin opened this issue Aug 19, 2020 · 7 comments
Open

yaf 3.2.5 CLI 模式运行参数接收不到呢? #506

hanwuqin opened this issue Aug 19, 2020 · 7 comments

Comments

@hanwuqin
Copy link

request.php

$request = new Yaf_Request_Simple("CLI", "Index", "Controller", "Hello", array("para" => 2));
print_r($request);

打印的结果:
[root@localhost cea]# php request.php
Yaf_Request_Simple Object
(
[method] => CLI
[module] => Index
[controller] => Controller
[action] => hello
[uri:protected] =>
[base_uri:protected] =>
[dispatched:protected] =>
[routed:protected] => 1
[language:protected] =>
[params:protected] => Array
(
)

)
params 无内容,和文档上的结果不一样呢:

   文档输出:           
 <?php
 $request = new Yaf_Request_Simple("CLI", "Index", "Controller", "Hello", array("para" => 2));
 print_r($requst);

运行输出:

 $ php request.php 
 Yaf_Request_Simple Object
 (
 [module] => Index
 [controller] => Controller
 [action] => Hello
 [method] => CLI
 [params:protected] => Array
 (
 [para] => 2
 )

 [language:protected] => 
 [_base_uri:protected] => 
 [uri:protected] => 
 [dispatched:protected] => 
 [routed:protected] => 1    //注意这里
 )
@hanwuqin
Copy link
Author

3.1.1版本可以正确实例化路由,最新版本不能正确实例化内容 是不是bug?

@laruence
Copy link
Owner

新版本中应该已经解决了,你可以测试下3.2.5

@hanwuqin
Copy link
Author

新版本中应该已经解决了,你可以测试下3.2.5

3.2.5 版本中还是存在cli 模式接收不到参数。
[root@localhost cea]# php --ri yaf

yaf

yaf support => enabled
Version => 3.2.5
Supports => http://pecl.php.net/package/yaf

Directive => Local Value => Master Value
yaf.library => no value => no value
yaf.environ => dev => dev
yaf.forward_limit => 5 => 5
yaf.use_namespace => 0 => 0
yaf.action_prefer => 0 => 0
yaf.lowcase_path => 0 => 0
yaf.use_spl_autoload => 1 => 1
yaf.name_suffix => 1 => 1
yaf.name_separator => no value => no value
You have new mail in /var/spool/mail/root
[root@localhost cea]#
[root@localhost cea]#
[root@localhost cea]#
[root@localhost cea]# php console console/message/trialUserExpire time 1

Array
(
)
缺少数据时间类型参数: time
yaf 3.1.4版本可以接收到参数
image

@MrJackDuaner
Copy link

Good afternoon,

I got a similar problem with yaf 3.2.5 and php-cgi.exe.

My configuration :

  • Root directory of Web App : C:\wwwroot\MyWebApp.
  • Web App URL : https://localhost/MyWebApp/
  • In configuration.ini, application.directory = "C:\wwwroot\MyWebApp\application"
  • In controllers directory, I got class IndexController with method IndexAction.
  • PHP 7.4.9.

The exception raised is : Failed opening controller script C:\wwwroot\MyWebApp\application\controllers\MyWebApp.php: No such file or directory

Before this test, I was using Yaf 3.1.2 with PHP 7.4.3 and it was running fine.

Here are all the tests done with yaf versions from 3.1.2 to the latest available :

  • 3.1.2 : OK.
  • 3.1.3 : No such file or directory.
  • 3.1.4 : No such file or directory.
  • 3.2.0 : Error 500.
  • 3.2.1 : Error 500.
  • 3.2.2 : Error 500.
  • 3.2.3 : No such file or directory.
  • 3.2.4 : No such file or directory.
  • 3.2.5 : No such file or directory.

Best regards,

MrJackDuaner

@laruence
Copy link
Owner

laruence commented Jan 5, 2021

trialUserExpire.php 大概是啥样的

@laruence
Copy link
Owner

laruence commented Jan 6, 2021

@MrJackDuaner you should check whether the PATH_INFO evn variable is set, and wether it is expected.

@MrJackDuaner
Copy link

@laruence

Good morning,

Sorry for the long period without any answer.

Last year, I didn't find the solution for PHP 7.4 / YAF 3.2.5.
This year, I'm migrating to PHP 8.0 and I wanted to use YAF 3.3.3. But i got the same error.
So, I found again this thread and I searched for a solution (I really took time to do it) with your last comment about PATH_INFO and I found it.

Here is the solution I have implemented.

index.php :
<?php
$_SERVER['PATH_INFO'] = $_GET['path_info'] ?? '';
$application = new Yaf_Application("configuration.ini");
$application->bootstrap()->run();

As I am working with IIS, the rewrite rule in web.config is :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite for path info" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?path_info={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Thank you for pointing it in the right direction.

I don't know if @hanwuqin has solved his issue, but for me it's good now.

Thank you.

Best regards,

MrJackDuaner

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

3 participants