Kohana v3.30 subfolders routing - frameworks

I've a small problem with subfolders routing, it's a lot of questions abaut routing in kohana, but I wrote it all, and I still have a problem, I add in boostrap this lines :
Route::set('admin', 'folder(/<controller>(/<action>(/<id>)))')
->defaults(array(
'directory' => 'folder',
'controller' => 'test',
'action' => 'pokaz',
));
I have folder in my controller folder (application/Controller/folder), my controller :
class Controller_Folder_Test extends Controller {
public function action_pokaz() {
echo "dasdsadsad";
}
}
When i writing this url:
1. http://example.com/kohana/index.php/test/pokaz - (Kohana - not found url)
2. http://example.com/kohana/index.php/folder/test/pokaz - (Kohana - not found url)
3. without /index.php/ - 404 Not found - Apache
So i really don't know what i'm doing wrong

ok it's working, i changed the folder name from "folder" on "Folder" and thats all :D Thx for help anyway ;]

Related

All Dingo routes return 404 when phpunit testing

original posted at https://github.com/dingo/api/issues/1472
I'm using Lumen 5.1 and DingoApi 1.0.x to do my api development, and now I'm trying to do some acceptance testing. Following the documentation of Lumen, here is how I do it:
Here is a simplified routes definition in app\Http\routes.php:
$app->get('/', function () use ($app) {
return "Welcome to mysite.com";
});
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
$api->group([
'prefix' => 'dealer',
'middleware' => 'checkH5ApiSign'
], function ($api) {
$api->get('list', 'App\Http\Controllers\Credit\DealerController#index');
$api->get('staff_list', 'App\Http\Controllers\Credit\DealerController#getStaffList');
});
}
I can access both routes defined using $app or $api(dingo) in browser or via postman, they both can return a 200 response. But whenever I'm trying to access those routes in phpunit, the $app defined route like / is responding okay with 200 code, but all routes defined with $api(dingo) will response with 404 status code. Here is my test code:
class DealerTest extends TestCase
{
public function testTest()
{
$this->get('/')->assertResponseOk();
$this->get('/dealer/list')->assertResponseOk();
$this->get('/dealer/staff_list')->assertResponseOk();
}
}
and ran result:
PHPUnit 5.7.5 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 590 ms, Memory: 6.00MB
There was 1 failure:
1) DealerTest::testTest
Expected status code 200, got 404.
Failed asserting that false is true.
E:\Gitrepos\api.fin.youxinjinrong.com\vendor\laravel\lumen-framework\src\Testing\AssertionsTrait.php:19
E:\Gitrepos\api.fin.youxinjinrong.com\tests\DealerTest.php:8
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
I tried ran through Dingo package code to find the cause, but failed. All other related issue could not solve my problem either. So please help me.
update
I followed the code flow, and see that FastRoute\DataGenerator\RegexBasedAbstract.php is doing the addRoute() operation, I dumped $this->staticRoutes) in that addRoute() method, see that it's doing okay both inside browser and under phpunit. But weird enough, the following call of ->getData() is behaving differenctly: in browser all static routes are returned, but not in phpunit.
Hope this can somehow be helpful. I'm still digging this problem...
So I got mine to work by doing this;
Using the example in the example used in creating the issue:
class DealerTest extends TestCase
{
public function testTest()
{
$this->get('/')->assertResponseOk();
$this->get('/dealer/list')->assertResponseOk();
$this->get('/dealer/staff_list')->assertResponseOk();
}
}
becomes
class DealerTest extends TestCase
{
public function testTest()
{
$this->get(getenv('API_DOMAIN') . '/v1/')->assertResponseOk();
$this->get(getenv('API_DOMAIN') . '/v1/dealer/list')->assertResponseOk();
$this->get(getenv('API_DOMAIN') . '/v1/dealer/staff_list')->assertResponseOk();
}
}
I hope this helps

Namespace missing

I have following class in folder frontend/migrations
use yii\db\Schema;
class m170727_180101_Bewerbungen extends \yii\db\Migration
{
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable('bewerbungen', [
'bew_id' => $this->primaryKey(),
'datum' => $this->date()->notNull(),
'firma' => $this->string(100)->notNull(),
'rechtsart' => $this->integer(11),
'stadt' => $this->string(100)->notNull(),
'plz' => $this->integer(11)->notNull(),
'strasse_nr' => $this->string(100),
'ansprech_person' => $this->string(100),
'email' => $this->string(50)->notNull(),
'feedback' => $this->integer(11),
'bemerkungen' => $this->string(150),
'FOREIGN KEY ([[feedback]]) REFERENCES nachricht ([[id_message]]) ON DELETE CASCADE ON UPDATE CASCADE',
'FOREIGN KEY ([[rechtsart]]) REFERENCES rechtsform ([[id_recht]]) ON DELETE CASCADE ON UPDATE CASCADE',
], $tableOptions);
}
public function safeDown()
{
$this->dropTable('bewerbungen');
}
}
Each try to read out method safeUp() throws out error:
Unable to find 'frontend\migrations\m170727_180101_Bewerbungen' in file: E:\xampp\htdocs\Yii2_Mail/frontend/migrations/m170727_180101_Bewerbungen.php. Namespace missing?**
Here is my script:
namespace frontend\migrations; ...
$connect=new m170727_180101_Bewerbungen();
$connect->safeUp(); ...
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
What the hell is that?
The same error using like this:
$connect=new \frontend\migrations\m170727_180101_Bewerbungen();
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Try using the full path
$connect=new \frontend\migration\m170727_180101_Bewerbungen();
You have got this error because there is no namespace in your file so autoloader can not find it.
But this is not the real problem here - you are not using Yii 2 migration properly. Follow the Yii2 Migration Guide.
In addition, since you placed this migration in frontend you might want to take a look at Namespaced Migrations to actually add namespace there and to run it properly.

How to fix error "Cannot dispatch middleware Application\Middleware\IndexMiddleware"?

I've set up a Zend Application as normal, except in my case the difference is that I set it up over an existing legacy web application.
I still want to call my existing legacy application over the ZF3 app. It was suggested I can do so using Middleware. I went over https://docs.zendframework.com/zend-mvc/middleware/ and set up my routing as described there.
However, when I run the application, I am greeted by this:
Cannot dispatch middleware Application\Middleware\IndexMiddleware
#0 zend-mvc\src\MiddlewareListener.php(146):
Zend\Mvc\Exception\InvalidMiddlewareException::fromMiddlewareName('Application\\Mid...')
Here is where the exception happens:
https://github.com/zendframework/zend-mvc/blob/release-3.1.0/src/MiddlewareListener.php#L146
Just to note:
$middlewareToBePiped; //'Application\Middleware\IndexMiddleware'
is_string($middlewareToBePiped); // true
$serviceLocator->has($middlewareToBePiped);//false
$middlewareToBePiped instanceof MiddlewareInterface; //false
is_callable($middlewareToBePiped);//false
My class is:
namespace Application\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Zend\Http\Response;
class IndexMiddleware implements MiddlewareInterface
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{}
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{}
}
I am thinking that my issue is that my IndexMiddleware class is not being found in ServiceLocator... (line 142 of linked API). How do I get it in there?
I put this into my application.config.php file:
'service_manager' => [
'invokables' => array(
'middleware' => IndexMiddleware::class
)
]
onto the next error it is.. (Last middleware executed did not return a response.)
but looks like it has executed)

Laravel Mail::Send works on local apache but complains about mime on nginx

I have installed a laravel package for user verification
https://github.com/jrean/laravel-user-verification
Register Controller needs to be changed to work like below.
public function register(Request $request)
{
$this->validator($request->all())->validate();
$user = $this->create($request->all());
$this->guard()->login($user);
UserVerification::generate($user);
UserVerification::send($user, 'Verification Mail from example.com');
return redirect()->intended('/home');
}
Used mailgun to send mails.It worked fine on local apache. sent mails successfully to gmail and others.
Installed on nginx production(ubuntu 16.04 VPS ). It throws following error.
FatalThrowableError in SimpleMessage.php line 33:
Type error: Argument 1 passed to Swift_Mime_SimpleMessage::__construct() must
be an instance of Swift_Mime_HeaderSet, none given, called in /var/www/example.com/
html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Message.php on line 48
To check if it is a package problem I have also done the following which works on local apache but throws the same error on nginx.
Route::get('/mailsend', function() {
$data = [
'title' => 'hello user',
'content' => 'Thanks for joining us'
];
Mail::send('mails.test', $data , function($message) {
$message->to('example#gmail.com','example')->subject('Testing from example');
});
});
The code as shown in error /Swift/Message.php in line 48 as follows
call_user_func_array(
array($this, 'Swift_Mime_SimpleMessage::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.message')
);
Could not figure out the problem with nginx. Any help would be greatly appreciated.
Try uncomment line: extension=php_openssl.dll on php.ini
and check this https://laravel.io/forum/05-13-2014-smtp-mail-not-working-in-live-server

Invalid controller using custom routes

I've been following the instruction on how to create custom routes from the book Zend Framework - A Beginners Guide
I've changed my application.ini file to include this routing information:
resources.router.routes.static-content.route = /content/:page
resources.router.routes.static-content.defaults.module = default
resources.router.routes.static-content.defaults.controller = static-content
resources.router.routes.static-content.defaults.view = static-content
resources.router.routes.static-content.defaults.action = display
Given the above configuration, I have this controller:
<?php
class Default_StaticContentController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function displayAction()
{
// action body
$page = $this->getRequest()->getParam('page');
if (file_exists($this->view->getScriptPath(null) .
'/' . $this->getRequest()->getControllerName() . '/' .
$page . $this->viewSuffix
)) {
$this->render($page);
}
else {
throw new Zend_Controller_Action_Exception('HLC - Page not found', 404);
}
}
}
I have a view named about.phtml in the APPLICATION_PATH/modules/default/views/static-content folder.
What ahppens is I get an error saying:
An error occurred
Page not found
Exception information:
Message: Invalid controller class ("StaticContentController")
Stack trace:
#0 /Applications/MAMP/htdocs/zend/library/Zend/Controller/Dispatcher/Standard.php(262): Zend_Controller_Dispatcher_Standard->loadClass('StaticContentCo...')
#1 /Applications/MAMP/htdocs/zend/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#2 /Applications/MAMP/htdocs/zend/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#3 /Applications/MAMP/htdocs/zend/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#4 /Applications/MAMP/htdocs/HLC/public/index.php(26): Zend_Application->run()
#5 {main}
Request Parameters:
array (
'page' => 'about',
'module' => 'default',
'controller' => 'static-content',
'view' => 'static-content',
'action' => 'display',
)
Note that it is not rendering my customised Zend_Controller_Action_Exception but throwing the global error.
I'm using the URL: http://hlc.local:8888/content/about
The default index action works ok, just this routing that's not working.
if you are actually following the book closely, you have an extra line in your route declaration and your controller class should be StaticContentController.
here is the route definition from the book that does work.
resources.router.routes.static-content.route = /content/:page
resources.router.routes.static-content.defaults.module = default
resources.router.routes.static-content.defaults.controller = static-content
resources.router.routes.static-content.defaults.action = display
I still have this code laying around from last summer.
I found this book less then satisfactory and not really for beginners. It fails to address the Zend_Db component opting instead to introduce Doctrine 1.2. It's seems to be a trend that a number of these beginner/easy books feel that a full ORM is more useful then Zend_Db. If you are already familiar with Doctrine this approach works fine, otherwise it's a lot to ask of a beginner, to learn ZF and Doctrine at the same time.
Hope this helps.
I don't now what you use for autoloading. so that would helpful to determine.so far I understand your class named should be something like this ModulePath_ApplicationPath_ControllerName, so its Default_Application_StaticContentController.
and for better routing I preferred zend manual. you can try this tutorial for route. it would help for you.