codeigniter4 - How do I shorten the path to the view folder for modules? - codeigniter-4

Based on a video with Codeigniter4, I created the Modules folder on the ROOTPATH and the Controllers, Views..etc folders in the Modules folder. It works fine, but when I want to call my view file inside the module
<?php
namespace Modules\Giris\Controllers;
use App\Controllers\BaseController;
class IndexController extends BaseController
{
public function index(){
return view('Modules\Giris\Views\index');
}
}
I need to specify a very long path like How can I make it just like view('index') and call the file from the Views folder in that module if I write it in a module? I don't want to write "Modules\Login\Views" in short is this possible?
Thanks in advance for all the kind replies.

Because view requires a string you couldn't provide a namespaced reference as you might think you should. Furthermore the code adds a .php extension and the "view path" (defined in your config\paths file) as part of its process (see system/View/View.php and render()). Therefore without modifying Codeigniter (which could be done but would affect all your code) the easiest way is to simply declare a public property or constant and make reference to that instead. Also helps if you need to change the path at any point.
I.e. protected $path = 'Modules\Giris\Views\' and then view($this->path.'index'); is probably the easiest way.

Related

Custom addon component not found

I'm trying to create a component within an addon. Everything works fine during impex process (contentslot, pagetemplate etc.) but it doesn't get rendered when accessing the page.
I've followed these steps but my controller isn't even get called.
#Controller("ConfirmationComponentController")
#RequestMapping(value = ControllerConstants.Actions.Cms.ConfirmationComponent)
public class ConfirmationComponentController extends AbstractCMSAddOnComponentController<ConfirmationComponentModel> {
#Override
protected void fillModel(HttpServletRequest request, Model model, ConfirmationComponentModel component) {
}
}
I've added the component's jsp in "WEB-INF/views/responsive/cms/.." from the addon module but I keep getting this error:
File [/WEB-INF/views/addons/trainingcore/responsive/cms/confirmationcomponent.jsp] not found
P.S.: I've managed to get the component controller to be called, but the getView() is returning a wrong path and that's why the component is not getting called. Any help? Thank you very much:)
Should this component to be created in addon *-items.xml?
What you need to know first
Using addons is a complicated endeavor in hybris. You need to know, that the resources are not used in the addon, but they are copied (during build process) to your storefront, where they are used.
All classes in
myaddon/acceleratoraddon/web/src/
will be copied to:
mystorefront/web/addonsrc/myaddon/
All resources in
myaddon/acceleratoraddon/web/webroot/
will be copied to corresponding folders:
mystorefront/web/webroot/WEB-INF/_ui-src/addons/myaddon
mystorefront/web/webroot/WEB-INF/tld/addons/myaddon
mystorefront/web/webroot/WEB-INF/messages/addons/myaddon
mystorefront/web/webroot/WEB-INF/tags/addons/myaddon
mystorefront/web/webroot/WEB-INF/views/addons/myaddon
That means
That means, that the effective path to your component jsp will not be something like:
/WEB-INF/views/cms/...
but will be something like:
/WEB-INF/views/myaddon/cms/...
The path myaddon will depend on the extension your component is declared in. So if you declare it in trainingcore-items.xml it will be
/WEB-INF/views/trainingcore/...
If you declare it in myaddon-items.xml it will be
/WEB-INF/views/myaddon/...

How are directory listings generated with ratpack?

I've just started looking at Ratpack, and my initial use case to as a simple development server. It seems quite trivial to get it to serve a directory of static files (in Groovy), I paraphrase this article:
#!/usr/bin/env groovy
#Grab('io.ratpack:ratpack-groovy:1.5.1')
import static ratpack.groovy.Groovy.ratpack
ratpack {
handlers {
files { dir "static" index }
}
}
I see there's an option to define an index page (for example, index.html), but this is static. I'd like it to serve a dynamic directory listing, as Apache can. I'd hoped this would simply require enabling a option, but I cannot find any indication such a thing exists.
I can't help feeling I have missed something. Can anyone point me in the right direction?
There's no built in directory listing feature. You would have to implement your own.

Prestashop | Remove transplant restrictions

So, there's a problem - I need to transplant "Categories Block" module to "displayTopColumn" hook (yep, designer put categories list near (on?) slider). But, by default, there is no possibilities to do this. I don't like that awful Prestashop restrictions, so maybe there is solution for this problem - remove those restrictions?
Thanks.
Removing those restrictions would not resolve anything for a simple reason: if you could hook the module blockcategories to displayTopColumn, this module would not know what to display in this hook because there is no hookDisplayTopColumn() function in it.
However, you can modify the module, and add a function to manage this hook.
To do so, open the file blockcategories.php and add the following:
public function hookDisplayTopColumn($params)
{
// Your code
}
If you want to display here the same content as in the hookLeftColumn hook, you can simply do this:
public function hookDisplayTopColumn($params)
{
return $this->hookLeftColumn($params);
}
You can also create your own function and template by copying, pasting and modifying the code you can find in the function hookLeftColumn() or in the function hookFooter().

How do i instantiate a UIMap in Class file that i have created

I"m trying to instantiate a UIMAp (the reason i need this is currenly i'm having an error thats occuring and i think its because i need to instantiate it). I've read online about how to do it but my UI maps are named the same as my cs files that are created. and i cant seem to see if i'm actually instantiating it correctly since its just a class. I have reference in the file
which is
using Microsoft.VisualStudio.TestTools.UITest.Common.UIMap;
But i dont think i'm accessing it or am i and just dont know
I tried this code HomePage MyNewUIMap = new HomePage();
but i don't believe its correct here is my folder structure
For example my folder and file structure is
--> Home (folder)
---->HomePage.uiTest(UIfile)
------->HomePage.cs (file)
----------->HomePage.Designer.cs (file)
I normally keep a utility class that does nothing but instantiate my maps. Then, I can just call MyUtility.HomePage.objectOnHomePage when I need to interact with that object, and I don't need to instantiate each map on each test class. However, the actual method for instantiating my maps is done below:
public HomePage myHomePageMap
{
get
{
if (_homePage == null)
_homePage = new HomePage();
return _homePage;
}
}
private HomePage _homePage;
I do it this way to make sure that, if I've already instantiated the map, I don't create a duplicate instance of it.

Autoloading a class in Symfony 2.1

I'm porting a Symfony 1.2 project to Symfony 2.x. I'm currently running the latest 2.1.0-dev release.
From my old project I have a class called Tools which has some simple functions for things like munging arrays into strings and generating slugs from strings. I'd like to use this class in my new project but I'm unclear how to use this class outside of a bundle.
I've looked at various answers here which recommend changing app/autoload.php but my autoload.php looks different to the ones in the answers, maybe something has changed here between 2.0 and 2.1.
I'd like to keep my class in my src or app directories as they're under source control. My vendors directory isn't as I'm using composer to take care of that.
Any advice would be appreciated here.
Another way is to use the /app/config/autoload.php:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add( 'YOURNAMESPACE', __DIR__.'/../vendor/YOURVENDOR/src' );
// intl
if (!function_exists('intl_get_error_code')) {
require_once _DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
Just replace YOURNAMESPACE and YOURVENDOR with your values. Works quite well for me, so far.
You're correct, I stumbled upon the changes in autoload from 2.0 to 2.1. The above code works fine with the latest version, to which I upgraded my project ;-)
For a simple case like this the quickest solution is creating a folder (for example Common) directly under src and put your class in it.
src
-- Common
-- Tools.php
Tools.php contains your class with proper namespace, for example
<?php
namespace Common;
class Tools
{
public static function slugify($string)
{
// ...
}
}
Before calling your function do not forget the use statement
use Common\Tools;
// ...
Tools::slugify('my test string');
If you put your code under src following the proper folder structure and namespace as above, it will work without touching app/autoload.php.

Resources