I've got a Zend-Framework application. I'm using the module-structure which Zend_Controller_Frontprovides. Here is a small excerpt from my directory-structure (only the important parts for this question):
root-directory
- modules
- blog
- views
- scripts
- index_index.phtml
- views
- pagination_control.phtml
As you can see I've got view-scripts that are specific to a module/controller/action. These views are located in the corresponding path (in this case like modules/blog/views. I've also got a more general view-directory located in the root-direcetory of my application.
What I am doing now is to call the PaginationControl-ViewHelper in modules/blog/views/scripts/index_index.phtml. This View-Helper however renders a partial-view, as you know. The ViewHelper tries to locate the partial-view within the same directory (meaning modules/blog/views/scripts. Since I want to use the same view-partial-script (pagination_control.phtml) in different modules I want to make this view-partial accessable from each module. So I want to put that file in the general views-folder in the root-directory.
However this doesn't work. The ViewHelper always looks for the view-script in the corresponding module-folder.
Anyone can help to make it accessable from my general views-directory?
As you can see here, since ZF 1.6.2 pagination control can take an array instead of a string for the partial argument, and in this array you set 1st the name of the partial and in 2nd the module name. This is still undocumented.
Using an array you can specify a module ('common'?) for the partial to use.
The real call will be (with $partial your 3rd argument to the paginationControl() view helper ):
$this->view->partial($partial[0], $partial[1], $pages);
This is usefull if you have a 'common' module.
Now here you are using a shared folder. You shoudl have installed it as a shared folder for your Zend_View this way (in a Boostrap or ressource code):
$view->addScriptPath("/root-directory/views");
or better:
$view->addScriptPath("/root-directory/views/partials");
And then you should'nt be required to specify any module directory. Zend_View should always check for a partial in this folder.
Related
I am trying to give a shot to HMVC in Codeigniter. Here is my folder structure.
-ROOT
--APPLICATION
---MODULES
----Module_Email
-----Controllers
-----Models
-----Views
-----Assets
------JS
------CSS
------IMG
To render the Module i have to use
Module::run('Module_Email');
This method will output the rendered output, an example is given below
<script type="text/javascript" src="PATH/TO/EMAIL_MODULE/JS/JS_FILE.JS"></script>
<div data-module-name="Module_Email" class="Email_wrapper">
//RENDERED HTML CONTENT
</div>
Now here my problem start. Normally i would like to put all my resources to header. So when i call any module, its dependence need to be added in header instead of from where its get called.
I searched a lot but i couldn't find any good methods.
Please help.
Update
Currently i have a function on my header called get_assets() which will output predefined resources to header. But i cant say which modules is going to use in pages, so the system need to check which modules are used in this page, and if its used then its dependencies need to be added on header.
Seems like your main problem then is trying to figure out what modules were used.
Unfortunately as far as I can tell with the default Wiredesignz modular extension there is no way to access the module name unless you write some sort of hack to get at that data. The module being used is stored in the protected variable $module in the MX_Router class, however, there is no public method to allow you to get access to it. So your only choice would be to extend the class and create a public function.
Alternatively you could use a forked version of Wiredesignz implementation which I did which provides numerous other features including a public function to get at the $module variable. Using the forked version I wrote you could then use code such as this:
<?php $module_name = $this->router->fetch_module(); ?>
However, that will only record the last module you loaded, so you would still need to do work to store all the modules, and then have your function use this information to determine what assets to load. If I were doing something like you I would probably fork my version and then create an additional data structure to store every module that was loaded that you could then later get access to.
I don't think this is exactly what you were hoping for, but might be something to get you on the right track to finding a solution.
I added an array to the Module class to store the assets and two functions to store/retrieve the items. Here is the source (updated Modules.php)
# Register your assets
public static function register_asset( $asset )
{
if( in_array($asset,self::$assets) === FALSE )
{
self::$assets[] = $asset;
}
}
public static function assets()
{
return self::$assets;
}
and now you can register your assets like this inside your module
Modules::register_asset('myslider.js');
You can retrieve all your assets using
Modules:assets();
Which will return an array of assets that can be processed depending up on the situation.
I'm working on my own module. I realize I constantly need to manually type my module name in different places. Most popular usage is with drupal_get_path($type, $name) function (I have more then 10 of these in my code). Where $name is theme or module name. During that time I need to already change my module name 3 times. As you can surmise I also need change all module names hard-coded in my project. So I thought it would be nice to have some convenient function to grab this name automatically.
How can I get machine module name programmatically?
For example if you have your module in following directory..
sites/all/modules/my_module/
..then you can grab it in this way
drupal_get_current_module_name(); // return my_module
Generally, you should know by convention - if you have: sites/all/modules/my_module/ then the machine name of the module should match the folder name - my_module.
Virtually all contributed modules follow this convention, and you should too.
It is possible to have your .info and .module file not match the name of the folder, but this isn't correct.
If you are already executing code inside your module, you should already know the machine name of the module by virtue of the name of the file you're editing - unless you're trying to do something that I'm not understanding.
Edit: Since we've determined you're just trying to call your module's theme function, you don't actually need to know the name.
If you have:
/** Implements theme_table **/
function my_really_long_module_name_table() {}
Your function might get called like this:
theme('table');
There is a little more to it than that, but the theme engine will make a determination about which theme functions get called based on what is implementing them.
It sounds like you may want to read up on some of the basics of the Drupal theme system.
Here's a good start for learning the Drupal 6 theme layer: http://drupal.org/node/165706
I figure out something like this:
function get_current_module_name() {
return array_shift(explode('.', end(explode(DIRECTORY_SEPARATOR, __FILE__))));
}
but don't know is't the best way to do it..
UPDATE:
I see now it's better to use basename
$name = basename(__FILE__, '.module');
UPDATE 2:
I think if this is needed across whole module then it could be accessible via constant defined in the very beginning of the module e.g.:
define('MODULE_NAME', basename(__FILE__, '.module'));
Then you could use all the time in all your function like this:
drupal_get_path('module', MODULE_NAME);
I want to add format pattern to format dial numbers as an xml file to the data directory of zend_locale_data. At the moment there are no format patterns available via CLDR, so i want to add it to my local zend framework environment.
As mentioned here, comment of Thomas Weidner at 26/Nov/07 2:04 AM, there is a way, but I can not find the file (file name is not written in that post) in the data directory (not in ZF 1.0.2 or in a newer one: e.g. 1.11.3).
I can not extend the Zend/Locale/Data.php and add a new case "dialnumber" to the switch-case in getContent(), because there are some private vars used (instead of protected) in getContent().
How to add a own "dialNumber.xml"?
I am using the following code in action class of a module XYZ:
$this->setTemplate("abc.php");
In which directory, it is trying to find abc.php?
The corresponding path is the templates directory that is parallel to the actions directory in which you are editing the actions.class.php file.
Within the file /path/to/my/module/actions/actions.class.php, if you do this:
$this->setTemplate("index");
The corresponding template file will be located at:
/path/to/my/module/templates/indexSuccess.php
This of course assumes successful completion of the action; upon failure, the handling is different and depends on your implementation.
Also worth noting:
If you don't set a template manually using $this->setTemplate($foo), the template name is determined by convention. For the action function executeHomepage(sfWebRequest $request),
the template homepageSuccess.php will be shown by convention (again, unless you specify otherwise with setTemplate).
See http://www.symfony-project.org/gentle-introduction/1_4/en/06-Inside-the-Controller-Layer#chapter_06_sub_action_termination. This documentation page contains comprehensive list of possible template names.
To be clear. Call
$this->setTemplate("abc");
will force Symfony to render template module/templates/abcSuccess.php if coressponding action method returns sfView::SUCCESS or nothing.
module/templates/abcError.php will be rendered if your action will return sfView::ERROR.
Also if your action is terminated with return 'SomeString'; then module/templates/abcSomeString.php is to be rendered.
According to API Documentation:
any time i write this:
$this->setTemplate('action_name', 'module_name');
I'm using a common set of javascript across several Symfony modules. I'd like to output the current module url-key as a javascript variable, so the javascript can use it to construct urls for various AJAX calls. I can't find where to get it, though.
$sf_context->getModuleName();
returns the module name, but not how it appears in the URL. I get that I could parse the module name from window.location, but that not only seems a bit crude, but I will soon have a case where I construct a url to a different module than the one that generated the current page.
How does one get the URL-key for the current (or given) module? Surely that mapping exists for the front controller.
To get the exact value as it was written in the url you can use custom routings. In symfony you can create a routing rule with the module name as a variable in the url. This variable named whatever you want will then be available in your action.
For example (app/*yourAppName*/config/routing.yml):
the_name_of_your_route:
url: thisIsAUrl/:variableYouWantWithWhateverCase
param: { module: yourModuleName, action: yourActionName }
Your url: param can even have regEx and wildcards in them if you like.
So now when you are in your executeYourActionName function a variable named variableYouWantWithWhateverCase will be set in the request exactly how it was typed in the url.
Hope this helps.
You can get the url-value of the current module with:
$sf_params->get('module'); // in templates
and
$request->getParameter('module'); // either this
$this->getRequestParameter('module'); // or this in the actions
and for constucting URLs to other modules I can use url_for(), though I couldn't get the module url-value alone via this method (it generates an entire url).