Zend Framework Rerouting for Friendly SEO URL? - zend-framework

I don't even understand where to start using the documentation and it's instructions. A little dumbfounded.
I have the URL : http://www.site.com/test/view/?aid=155 right now.
I want it to show up as http://www.site.com/test/155 (Using controller "test" and action "view" with parameter aid as 155)
and for future learning experiences, how would I do http://www.site.com/madeupname/155
Where would I start? What file?
What do I put in it?
Please and thank you!!!!!

It's not that hard to do, especially if you use an .ini file for your routes.
Create a routes.ini file inside of your /site/application/configs folder.
For example :
[production]
routes.home.route = /home/
routes.home.defaults.controller = index
routes.home.defaults.action = index
routes.login.route = /login/:username/:password
routes.login.defaults.controller = index
routes.login.defaults.action = login
routes.login.defaults.username = username
routes.login.defaults.password = password
and then bootstrap it
(inside bootstrap.php, add this)
/*
* Initialize router rewriting via .ini file.
*/
protected function _initRewrite()
{
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addConfig(new Zend_Config_Ini(APPLICATION_PATH. "/configs/routes.ini",
'production'), 'routes');
}
You could then access the login page with www.site.com/login/yourname/yourpass
or get to the home page via www.site.com/home
http://www.devpatch.com/2010/02/load-routes-from-routes-ini-config-file-in-zend-application-bootstrap/
http://framework.zend.com/manual/en/zend.controller.router.html

Related

RealURL with GET parameters

We have developed a typo3 plug in that searches for trucks. For SEO reasons, we are trying to use the realURL plug in to make the URLs friendlier to use.
On the front page we have several call to actions that link to the search page with certain search parameters. An example is bellow:
/search-results/?tx_fds_searchresults[type_name]=Trailer
This link works as expected. On the results page is a link to the listings page with more details. An example is bellow:
/listing/?tx_fds_listing[id]=119870
This link is not working. tx_fds_listing[id] is not being populated in the arguments passed to the plug in controller.
At first we thought it might be a config issue but again, it isn't present on other pages.
The ID is not a database object and may be a text string instead.
Edit:
I should add that it works fine with RealURL turned off.
We get the id as $id = $this->request->getArgument('id');
Edit 2:
Here is the error message from the logs.
[ALERT] request="28233e225150a" component="TYPO3.CMS.Frontend.ContentObject.Exception.ProductionExceptionHandler": Oops, an error occurred! Code: 201512141630381db91bba - {"exception":"exception 'TYPO3\\CMS\\Extbase\\Mvc\\Exception\\NoSuchArgumentException' with message 'An argument \"id\" does not exist for this request.'
I also tried renaming the variable to name, but that didn't work either.
I have a solution that solves the root cause of the problem, if not the specific issue.
So I had to add additional mapping to the realurl_conf.php file. For example to get the listing id:
$config['domain.com']['postVarSets'][3]['stock'] = array(array('GETvar' => 'tx_fds_listing[id]'));
This makes the effective URL:
/listing/stock/119870
This was the intended usage for the plugin, so this is a good result. I also added configuration for ajax and pdfs. This required modification to the typoscript that was not obvious.
PDF TS:
pdf = PAGE
pdf {
typeNum = 300
10 = USER_INT
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
#vendorName = TYPO3
extensionName = Fds
pluginName = Listing
#controller = FDS
controller = Tx_Fds_Controller_FDSController
#action = listingPdf
switchableControllerActions.FDS.1 = listingPdf
}
config {
disableAllHeaderCode = 1
additionalHeaders = Content-type:application/pdf
xhtml_cleaning = 0
admPanel = 0
}
}
PDF RealURL Config:
$config['domain.com']['postVarSets'][3]['pdf'] = array('type' => 'single', 'keyValues' => array ('type' => 300));
PDF effective URL:
/listing/pdf/stock/119870

how to make routing URL for our wish in zendframework using routes.ini file?

I need to the routing URL like the following
http://www.website.com/module-name/controller-name/{article-name}/{article-id}
i tried using the routes.ini file but it's not working
routes.index-latest.route = "index/latest/$1/:id"
routes.index-latest.module = "index"
routes.index-latest.defaults.controller = "latest"
routes.index-latest.defaults.action = "index"
routes.index-latest.defaults.id = ""
can you anyone suggest me on the issues or please tell me any other way to achieve the URL like through bootstrap file.
i searched on the net but i am not getting the right solution.
i fixed myself like example #
routes.index-latest.route = "index/latest/:article_id"
routes.index-latest.defaults.module = "module-name"
routes.index-latest.defaults.controller = "controller-name"
routes.index-latest.defaults.action = "action-name"
routes.index-latest.defaults.article_id = ""
routes.index-latest.defaults.reqs.article_id = "\d+{1,}"
in routes.ini

zend Navigation not right work cause zend router

my url is http://mysite.com/index/bytype/id/5/name/ACTION
when using zend router it'll be rewrite to http://mysite.com/index/bytype/5.ACTION.html
i was config in file router.ini like this:
routes.bytype.type = "Zend_Controller_Router_Route_Regex"
routes.bytype.route = "bytype/(\d+).(.*).html"
routes.bytype.defaults.module = "default"
routes.bytype.defaults.controller = "index"
routes.bytype.defaults.action = "bytype"
routes.bytype.map.1 = "id"
routes.bytype.map.2 = "name"
routes.bytype.map.3 = "page"
routes.bytype.reverse = "bytype/%d.%s.html"
code above have issue when i click button next page , it not jump to next page, cause Parameter page/2 not avalable, zend router was rewrite my url become to http://mysite.com/index/bytype/5.ACTION.html again,
if not rewrite it maybe look like http://mysite.com/index/bytype/id/5/name/ACTION/page/2
so how can i including "page" parameter into url above with zend router.thanks for reading
Try Zend routing on your Bootstrap.php file as an alternative.
Here is a tutorial on how to do that:
http://www.codexperience.co.za/post/hiding-url-parameters-names-using-zend-routers

Call TYPO3 plugin from other plugin's body

I need to call typo3 plugin from other plugin's body and pass its result to template. This is pseudo-code that describes what I want to achieve doing this:
$data['###SOME_VARIABLE###'] = $someOtherPlugin->main();
$this->cObj->substituteMarkerArray($someTemplate, $data);
Is it possible?
Thanks!
It doenst work if you use the whole pi construct, e.g. for links, marker function etc, and the TSFE Data can be corrupted.
Dmitry said:
http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1'];
$conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1.'];
$cObj = t3lib_div::makeInstance('tslib_cObj');
$cObj->start(array(), '_NO_TABLE');
$conf['val'] = 1;
$content = $cObj->cObjGetSingle($cObjType, $conf); //calling the main method
You should use t3lib_div:makeInstance method.
There is a working example from TYPO3's "powermail" extension.
function getGeo() {
// use geo ip if loaded
if (t3lib_extMgm::isLoaded('geoip')) {
require_once( t3lib_extMgm::extPath('geoip').'/pi1/class.tx_geoip_pi1.php');
$this->media = t3lib_div::makeInstance('tx_geoip_pi1');
if ($this->conf['geoip.']['file']) { // only if file for geoip is set
$this->media->init($this->conf['geoip.']['file']); // Initialize the geoip Ext
$this->GEOinfos = $this->media->getGeoIP($this->ipOverride ? $this->ipOverride : t3lib_div::getIndpEnv('REMOTE_ADDR')); // get all the infos of current user ip
}
}
}
The answer of #mitchiru is nice and basically correct.
If you have created your outer extension with Kickstarter and you are using pi_base then there is already an instance of tslib_cObj and the whole construct becomes simpler:
// get type of inner extension, eg. USER or USER_INT
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1'];
// get configuration array of inner extension
$cObjConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1.'];
// add own parameters to configuration array if needed - otherwise skip this line
$cObjConf['myparam'] = 'myvalue';
// call main method of inner extension, using cObj of outer extension
$content = $this->cObj->cObjGetSingle($cObjType, $cObjConf);
Firstly, you have to include your plugin class, before using, or outside your class:
include_once(t3lib_extMgm::extPath('myext').'pi1/class.tx_myext_pi1.php');
Secondly in your code (in the main as example)
$res = tx_myext_pi1::myMethod();
This will work for sure (I've checked this): http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html.
Probably Fedir's answer is correct too but I didn't have a chance to try it.
Cheers!

How to add two numbers in sugar crm

I made module addition and in this made three fields amount1_c, amount2_c and total_amount_c to add the two numbers and display the result in the third field. I done coding in the logic looks here is my code
<?
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1,'calculate_field', 'custom/modules/cases/LogicHookMath.php','LogicHookMath', 'calculate_field');
?>
and made one more file logic hook math. here is my code for
<?php
class LogicHookMath {
function calculate_field(&$bean, $event, $arguments) {
$field1 = $bean->amount1_c;
$field2 = $bean->amount2_c;
$field3 = $field1 + $field2;
$bean->amount_total_c = $field3;
}
}
?>
but still i did not get any result. Please help me out for this.
The code looks correct.
Some common "mistakes" when custom logic hooks are not working:
Make sure, the custom logic hook has the correct name (LogicHookMath.php)
Make sure, that the $bean variable is prefixed with &, so the variable is passed as a reference
Make sure the logic_hooks.php and the LogicHookMath.php files are readable by the web server user
The entire custom directory should also be writeable for the web server user
If the above does not help, try logging the progress to the sugarcrm.log using $GLOBALS['log']->info( "Value 3: ". $field3); in the custom logic hook.