Lithium/Apache on Mac : can't access to the view - lithium

I have installed Lithium and tested on Mac.
I can't access to the views that i defined. I can only access to the index file.
My simple project is firstLithium. I set it in /Library/Webserver/Documents
In this project, i create 1 view named posts. Here after is the content of my MVC.
models/Posts.php :
<?php
namespace app\models;
class Posts extends \lithium\data\Model {
}
?>
views/posts/index.html.php :
Lithium is less dense than ium.
controllers/PostsController.php
<?php
namespace app\controllers;
class PostsController extends \lithium\action\Controller {
public function index() {
return array('foo' => 'bar', 'title' => 'Posts');
}
public function add() {
}
}
?>
From web browser :
localhost/firstLithium : it works well
localhost/firstLithium/posts : it doesn't work
Not Found
The requested URL /firstLithium/posts was not found on this server.
The same example can run on ubuntu, but not on Mac. Can i help you to run it on Mac. Thank you in advance.

Definitely looks like a problem with your web server settings, and not Lithium.
Try this guide and if the problem persist, feel free to ping me in #li3 IRC channel.

Also, make sure you have mod_rewrite enabled, for Apache. I'm not sure what the command is, for a Mac, but on Linux, it's:
sudo a2enmod rewrite

Related

Sending ResetPassword notification using queue in Laravel 6 - error property 'view'

I want to override default notifications for password reset and email verification in laravel 6 to use queue in a simplest way as possible. So I add methods in User.php model:
use App\Notifications\ResetPasswordNotification;
use App\Notifications\EmailVerificationNotification;
...
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
public function sendEmailVerificationNotification()
{
$this->notify(new EmailVerificationNotification);
}
and create new notifications
ResetPasswordNotification
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Notifications\ResetPassword;
class ResetPasswordNotification extends ResetPassword implements ShouldQueue
{
use Queueable;
}
EmailVerificationNotification
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Notifications\VerifyEmail;
class EmailVerificationNotification extends VerifyEmail implements ShouldQueue
{
use Queueable;
}
Now email verification is sending queued, but in url as a host name is generating http://localhost/... In default notification it is generated correctly, the same one like a domain name in browser (without changing it in .env file).
The second problem is with password reset notification, which is not sending at all. It gives me an error
Trying to get property 'view' of non-object at vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php:92
and I don't understand why it is happening and don't working as expected.
Searching the problem I even found this (question) where fakemeta mention about it that should work.
I figured it out. First, when using queue, in my case I am running artisan queue:work with supervisor daemon, jobs are running under the console, so there is no SERVER['HTTP_HOST'] var available which mean than this value must be read from .env file. Second, when You change code overriding methods like I did, you must restart this queue:work to re-read changes. So those were my main problems.

How and where to instantiate a custom class that extends the WP_REST_Controller

I have a plugin that I created and I want to use the WP rest api controller pattern in order to extend the api.
<?php
/**
* Plugin Name: myplugin
* Plugin URI: h...
* Description: A simple plugin ...
* Version: 0.1
* Author: Kamran ...
* Author ....
* License: GPL2
function myplugin_register_endpoints(){
require_once 'server/controllers/my_ctrl.php';
$items=new items();
$items->register_routes();
}
add_action('rest_api_init','myplugin_register_endpoints');
.
.
I created a class a folder called server/controllers and inside it my_ctrl.php file with a class that extends WP_REST_Controller that looks like this
// server/controllers/my_ctrl.php
class items extends WP_REST_Controller {
/**
* Register the routes for the objects of the controller.
*/
public function register_routes() {
.....
}
}
However I am receiving the following error in sublime xdebuge call stack:
[Fatal error] Class 'myplugin\WP_REST_Controller' not found
I am not sure how to solve this issue, where to put the files for my custom controller, where to create the instance of the custom class etc?
Stumbled upon this and thought I'd provide my solution in case someone else encounters this.
The idea is to postpone the instantiation of the class extending WP_REST_Controller by not instantiating it until the actual rest_api_init hook is called.
Code example:
add_action( 'rest_api_init', function () {
require_once(plugin_dir_path(__FILE__) . '/VideoImageApi.php');
VideoImageApi::instance()->register_routes();
});
Note the require_once from within the callback.
I have manged to solve the issue,
I checked the wp-content\plugins folder and I couldn't find the \rest-api folder and although I found the folder inside \wp-includes\rest-api it seems that this folder that integrates the "wp rest api" into core doesn't include all the classes that the api can expose (it includes only 3 php files), So it didn't include \wp-content\plugins\rest-api\lib\endpoints\class-wp-rest-controller.php . I installed the "wp rest api" plugin and it was added to wp-content\plugins and now I don't have the error anymore. (It was strange because I don't know when it was deleted from my project)
Thank you Dan your comments really helped me to recheck everything and scan the folders included in my wordpress and realize that the plugin is missing and that the folder \wp-includes\rest-api doesnt contain all the needed classes.

Shared base controller between modules

I am setting up a multi-module application, so far I have it setup like this example http://docs.phalconphp.com/en/latest/reference/applications.html.
But I was wandering if its possible to have shared base controller that both the backend and frontend controllers extend from. This is so I can have a single ACL in the base controller. How would I set that up?
According to the docs I can create a controllerbase anywhere and then just require this file directly in the bootstrap file or cause to be loaded using any autoloader. So I created a folder called apps/shared/controllers/ControllerBase.php and required this file directly in the bootstrap file but this does not work.
If I try to load a controller like so:
class AdminController extends ControllerBase
{
public function indexAction()
{
echo "<h1>Hello admin!</h1>";
}
}
I get an error ...Backend\Controllers\ControllerBase' not found in......
So how do I cause to be loaded using any autoloader as per the docs? Do I need to register it as its own namespace or something?
You not using the full namespace path for your base controller so the autoloader attempts to find it under in the same namespace of the child class.
Try something like this:
namespace MyApp\Backend\Controllers;
use MyApp\Shared\Controllers\ControllerBase;
class AdminController extends ControllerBase
{
public function indexAction()
{
echo "<h1>Hello admin!</h1>";
}
}
This answer consider that you have applied the PSR-0 and PSR-4 properly.

kendo ui editorfor imagebrowser returns 403

I'm new to web development and I'm trying to implement the Kendo UI editor with an image browser to insert into the document on an MVC 4.5 page. the editor is working fine, however, when i click the insert image button i gt a 403 forbidden popup message.
I've created a custom image browser controller pointing to ~/Content/images.
and in my view, i am using the custom browser controller within my code
#(Html.Kendo().EditorFor(m => m.QuestionText)
.Encode(false)
.HtmlAttributes(new { style = "width: 100%; height: 200px" })
.Name("EditQuestionText")
.Tools(tools => tools.Clear().InsertImage())
.ImageBrowser(imageBrowser => imageBrowser
.Image("~/JFA/QuestionImages/{0}")
.Read("Read", "JFAImageBrowser"))
)
I've compared my code to the sample project from Kendo for the EditorFor (which will browse the folder) but can find no discernible differences... I also cannot find much in the way of other people who are having this problem so i suspect there is a setting that i cannot find that is causing my issue, any help would be GREATLY appreicated
my image browser (taken directly from the demo)
public class JFAImageBrowserController : EditorImageBrowserController
{
private const string contentFolderRoot = "~/Content/images";
public override string ContentPath
{
get
{
return contentFolderRoot;
}
}
additionally, using Fiddler the click event for the "Insert Image" button is
GET /JFA/JFAImageBrowser/Read?path=%2F HTTP/1.1
where as the demo is
POST /ImageBrowser/Read HTTP/1.1
I don't know why the demo is using a POST where as mine is using a GET, unless this is because of the overridden image browswer
That code looks fine. Can you make sure your JFAImageBrowser controller looks something like this?
public class BlogImagesController : EditorImageBrowserController
{
//
// GET: /BlogImage/
public ActionResult Index()
{
return View();
}
public override string ContentPath
{
get { return AssetFilePaths.BlogContentPath; }
}
}
It's important that it inherits from EditorImageBrowserController
Also, a 403 may mean that the user doesn't have permission to access the directory. Check the permissions for the user you're running as.
It turns out my problem was in the _Layout page. I was using bundling and either
A) I made some error when setting up the bundling
-or-
b) the bundling didn't work as expected/intended.
either way i added the individual script/java script references and it works as expected.
Here is the solution to this problem
the page this issue fixed was it kendo forum
http://www.telerik.com/forums/implementing-image-browser-for-editor
and the direct link for the demo
http://www.telerik.com/clientsfiles/e3e38f54-7bb7-4bec-b637-7c30c7841dd1_KendoEditorImageBrowser.zip?sfvrsn=0
and if this demo didn't work you can see this sample i made from above
https://www.mediafire.com/?9hy728ht4cnevxt
you can browse the editor through HomeController and the action name is homepage (home/homepage)
& I think that the error was in different uses of paths between the base controller & child controller you make.

setting the location of Form classes

I started writing my first Zend Framework 2.0 (beta 1) PHP application using php 5.3.
I actually created a skeleton project and module based on the following url: http://packages.zendframework.com/docs/latest/manual/en/zend.mvc.quick-start.html
I want to add forms to the module I created. the my question is how do I configure the module to know where to fetch the forms in?
my module name is called LoginModule and I created a new form called LoginForm (that extends Zend_Form) and I placed it in my_proj/module/LoginModule/src/LoginModule/forms
how do I configure that module to know where to fetch the form class from ?
thanks
found the answer at http://akrabat.com/getting-started-with-zend-framework-2/
Everything has changed... (got better) in zend framework 2.
I created a directory called 'Form' in the src directory of my module.
inside I create the class that extends Form (not Zend_Form)
example from the tutorial above:
<?php
namespace Album\Form;
use Zend\Form\Form,
Zend\Form\Element;
class AlbumForm extends Form
{
public function init()
{
$this->setName('album');
$id = new Element\Hidden('id');
$id->addFilter('Int');
$artist = new Element\Text('artist');
$artist->setLabel('Artist')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$title = new Element\Text('title');
$title->setLabel('Title')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$submit = new Element\Submit('submit');
$submit->setAttrib('id', 'submitbutton');
$this->addElements(array($id, $artist, $title, $submit));
}
}
i really recommend reading the tutorial for all zend framework 2 beginner :)
thanks!