Adding a view to Slim Views Framework with composer - php

I am writing a PHP template system for Slim, I have it working fine, but it is necessary to install the view file Ets.php in the correct existing location:
vendor/slim/views/Slim/Views/Ets.php
Whilst I can do it manually of course this defeats the object of composer. I was wondering if I can do it with https://getcomposer.org/doc/articles/custom-installers.md but I am having trouble following the guide as it and others only really talk about installing outside of the vendor directory.

Why do you want the views to get installed in the same place?
Have a look into http://docs.slimframework.com/#Custom-Views
You just need to extend the Slim\View. An example taken from the docs
class CustomView extends \Slim\View
{
public function render($template)
{
return 'The final rendered template';
}
}
and integrate in to slim like
$app = new \Slim\Slim(array(
'view' => new CustomView()
));
NB : Don't forget to do the autoload the classes required.

Related

laravel doesn't use published views

For my Laravel 5.5 project I used filemanager package (elfinder-laravel ) with published and adapted blade views. After awhile I found that default views are used from package folder:
/vendor/barryvdh/laravel-elfinder/resources/views
instead of published views:
/resources/views/vendor/elfinder
I tried to republish views, clear views and cache. But nothing helps, it still uses default package views.
Views in /resources/views/vendor/elfinder exist.
Any idea how to make it work?
Try to edit the service provider file to be like that :
public function boot()
{
$this->loadViewsFrom($this->app->resourcePath('views/vendor/elfinder'), 'elfinder');
}
It is forces the file to use this directory as main view directory instead of changing it.
The question is quite old, but you have to set in the
$this->loadViewsFrom(__DIR__.'/../resources/views', 'courier');
the same package name as in the
$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/courier'),
]);
(notice both times the courier)
See: https://laravel.com/docs/8.x/packages#overriding-package-views

Creating a PHP Web app from scratch using Slim as Architecture

This is my long quest to develop web apps using core PHP and follow the best possible practices and not using a framework. I have achieved many things by structuring my project a better way. However ...getting a clean URL is often a problem for large apps.
Till now...I have used the Slim Framework only for creating RESTFUL services outside my web apps.
I am using Slim Framework to create APIs for a PHP project. Now, I have an install of Slim up and running fine. I have my routes talking to the database and doing what they're supposed to do, generally. My question has to do with modularizing the code. At the moment, all my routes are defined in my index.php file in the root directory. I would very much like to separate these out, say into a /controllers folder.
As I liked the way Slim makes pretty good URLs...I am wondering if it is possible to use Slim as my app architecture ...and let all my pages or APIs be accessible through the Slim index.php.
Yes pretty easily here are the steps I have taken on a recent project.
First lets say your have a HomeActionController
class HomeActionController {
//The below line I have moved into an abstract Controller class
public $view = null;
//This is using Slim Views PhpRenderer
//This allows for a controller to render views can be whatever you need
//I did not like the idea of passing the whole DC it seemed overkill
//The below method I have moved into an abstract Controller class
public function __construct(\Slim\Views\PhpRenderer $view = null){
if($view != null){
$this->view = $view;
}
}
//View could be any action method you want to call it.
public function view(Request $request, Response $response, array $args){
$data['user'] = "John Doe";
return $this->view->render($response, 'templates/home.php', $data);
}
}
Now you need to be able to call an instance of this controller from a route so you need to add the controllers you have to the DC
Where ever you are creating your instance of slim you will need to get the DC and add an instance of your controller:
$app = new \Slim\App($config['slim']);
// Get Dependency Container for Slim
$container = $app->getContainer();
$container['HomeActionController'] = new Controller\HomeActionController($container['view']); //Notice passing the view
As a note the above instantiations could have been a closures but I did not see the point at the time or making them. Also, there are ways to lazy load that I have not explored yet see here for more information.
Now the last thing you need to do is be able to call these on the routes which is not a huge challenge.
$app->get('/home', 'HomeActionController:view');
Granted you cannot have an action with parameters but I have not had an issue just passing them along in the request and then getting them from there.
If you want to create a app with no framework, then i would recommend looking through this small github repo:
https://github.com/PatrickLouys/no-framework-tutorial
It goes through with you settings everything up in terms of routing, plus would make everything go through the index.php in a public folder like your asking.

ZF2 EdpDiscuss module usage

I am new to ZF2. I am trying to use EdpDiscuss module, I've downloaded from here. I put the main file to modules, and added module to application.config.php. When I var_dump active modules
$modules = $this->getEvent()->getApplication()->getServiceManager()->get('modulemanager')->getLoadedModules();
$moduleNames = array_keys($modules);
var_dump($moduleNames);
It shows EdpDiscuss as it should, but how can I use it? There are no routes in module.config.php so it has no pages. I also tried to use it as service:
$service = $sm->getServiceLocator()->get('edpdiscuss');
but I was not succesfull either. Can you please tell me how to use this module?
Thanks
There is an example project you can use:
https://github.com/EvanDotPro/EdpForum
Basically, the service can be obtained with:
$discussService = $this->getServiceLocator()->get('edpdiscuss_discuss_service');
After that, you can use methods of the service by exploring its public interface:
https://github.com/EvanDotPro/EdpDiscuss/blob/master/src/EdpDiscuss/Service/Discuss.php

showing a module anywhere in website of codeigniter

I am pretty new to codeigniter and working on an audio cart website.
I implemented a audio playlist in my project and I created a different module called playlist. Created routes and everything working fine for the page playlist. I used HMVC codeigniter and hence i have different folders for each module.
My playlist is basically a list of songs and user can select and play any song.
Modules-
---Playlist
--Controllers
--playlist.php (my front controller)
--Models
--playlistmodel.php (model)
--Views
index.php (view for showing playlist)
Now according to new specifications, This playlist can be placed anywhere in the website. It should be working. I am not able to figure out how is this feasible ? should I need to create helpers ?
Please help .
Live Url : http://webcartz.stagetesting.com/playlist
Thanks
see this url:--
How to load a module outside modules folder on HMVC with CodeIgniter?
Well you can do this too
<?php echo Modules::run('../bar/bar/index'); ?>
Perhaps you should create a library then
When we use the term "Libraries" we are normally referring to the
classes that are located in the libraries directory and described in
the Class Reference of this user guide. In this case, however, we will
instead describe how you can create your own libraries within your
application/libraries directory in order to maintain separation
between your local resources and the global framework resources.
As an added bonus, CodeIgniter permits your libraries to extend native
classes if you simply need to add some functionality to an existing
library. Or you can even replace native libraries just by placing
identically named versions in your application/libraries folder.
http://codeigniter.com/user_guide/general/creating_libraries.html
something like this
class Playlistlib {
public function __construct($params)
{
$CI =& get_instance(); // so you'd use $CI instead of $this to ref to CI object
// Do something with $params
}
public function get_playlist($params)
{
// Do something with $params
}
}
$params = array('id' => 15, 'limit' => 5);
$this->load->library('Playlistlib', $params);

Zend Framework - Form class not autoloading

I'm getting
Fatal error: Class 'Form_Login' not found in /route/to/project/application/controllers/AuthController.php on line XX
when instantiating the class From_Login inside the controller.
I suppose the form is not being autoloaded by the bootstrap class.
In my bootstrap file I have this method
protected function _initAutoload(){
$modelLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH));
return $modelLoader;
}
supposed to autoload my resources.
I'm using the default project structure.
-application
--controllers
---Authcontroller.php
--forms
---Login.php
when I created the form with zf tool it automatically set the name as Application_Form_Login then I erased the Application_ part since I'm using "" namespace. I doesn't work either way.
I've also tried setting appnamespace="" in the application.ini file but nothing happened
After trying over and over different options I got tired because it didn't work so I erased the project folder and started from the beginning whit zend tool and ... voilĂ , it works!
In my opinion it was a problem with zend tool and/or the .zfproject.xml file since I was adding some resources manually and some others with the zf tool.
use Zend modular structure and change your class name 'Form_Login' to 'Default_Form_Login' .

Categories