Is there any way to route random string to dashboard in Codeigniter 3? - codeigniter-3

I have a question about Codeigniter: Is there any way to check function exists In the controller file and then route to the function path or else route it to a specific url?

I don't know what kind of Dashboard mean in your question.
I just answer how to check function exist or not in controller and route to that function.
In some case, you may need to add a route rule in config/routes.php.
$route['/programme/(.*)$'] = 'programme/programmes/$2';
Use method_exists() to check if function exist.
class Programme extends CI_Controller {
public function programmes($sub_part = NULL) {
if (!empty($sub_part) and method_exists($this, 'programmes_'. $sub_part)) {
return $this->{'programmes_'. $sub_part}(array_slice(func_get_args(), 1));
}
die('bar')
}
private function programmes_foo() {
die('foo')
}
}
When a visitor go to https://www.foobar.com/programme/foo (foo is something affect which function to call), your website should able to show foo. If the function is not exist, it show bar.

You can use
$route['product/(:any)'] = 'yourcontroller/your_function';
Source : https://codeigniter.com/userguide3/general/routing.html

i think you can change your route into this
$route[‘produk/(:num)/(:any)’] = ‘HomeControl/detail_produk/$1/$2’;
result from that route it's like this
http://www.localhost.com/produk/1/nama-produk-1
or maybe you can read the documentation CI 3 in this link or you can read my reference this link
i hope i can help you, thanks.

Related

VSCode extension API: simple local Quick Diff

Trying to understand how to implement simple source control management in my language extension.
I need to show a Quick Diff for a single file (my extension doesn't work with folders) compared with some special one.
Let's say i have this TextDocumentContentProvider and QuickDiffProvider:
class MyLangDocumentContentProvider implements vscode.TextDocumentContentProvider
{
provideTextDocumentContent(uri: vscode.Uri)
{
return getFileText(uri); // returns text of provided file uri
}
}
class MyLangRepository implements vscode.QuickDiffProvider
{
provideOriginalResource(uri: vscode.Uri)
{
return getOriginalFileUri(uri); // returns uri of the special file to compare with
}
}
Then in activate method of extension i initialize them:
const docProvider = new MyLangDocumentContentProvider();
const gitSCM = vscode.scm.createSourceControl('git', 'Git');
gitSCM.quickDiffProvider = new MyLangRepository();
const workingTree = gitSCM.createResourceGroup('workingTree', 'Changes');
workingTree.resourceStates = [
{ resourceUri: vscode.window.activeTextEditor.document.uri }
];
Then i need to call registerTextDocumentContentProvider with some custom uri scheme. So why do i need custom uri scheme? And what else should i do to track changes of current file relative to the special one?
I was looking at vscode-extension-samples/source-control-sample, but it looks more complicated then my case.
Thanks for any advices!
Though my question was rather sily, let me save here some kind of instruction, how I've done this.
to make QuickDif work you don't need neither ResourceGroups nor TextDocumentContentProvider, this is a separate functionality.
SourceControl (and also its quickDiffProvider) will work if you pass some root directory in constructor (I've got no luck without thoug I don't need it for my purpose).

SugarCRM: how to use preDisplay function in ViewQuickcreate?

I'm trying to customize the quick create view to add a default value of a field in Sugar Community Edition 6.5.24
Similar code works fine for ViewEdit, but it seems never called in subpanels.
Current file is
custom/modules/Opportunities/views/view.quickcreate.php
Unfortunately the constructor is not invoked.
Any help very appreciated.
<?php
require_once('include/MVC/View/views/view.quickcreate.php');
class OpportunitiesViewQuickcreate extends ViewQuickcreate {
function OpportunitiesViewQuickcreate(){
parent::ViewQuickcreate();
}
function preDisplay() {
parent::preDisplay();
$_REQUEST['custom_field_c'] = "a value for this field";
}
}
After tens of trying, I've found solution.
The right way is to extend SubpanelQuickCreate in the file custom/modules/Opportunities/views/view.subpanelquickcreate
require_once('include/EditView/SubpanelQuickCreate.php');
class OpportunitiesSubpanelQuickcreate extends SubpanelQuickCreate {
function OpportunitiesSubpanelQuickcreate() {
$_REQUEST['custom_field_c'] = "a value for this field";
parent::SubpanelQuickCreate("Opportunities");
}
}
Going from memory, so I may be wrong, but try adding $this->useForSubpanel = true; in your constructor.

How to use a helper

I am creating a module that allows a user to input details into a form and save their details to allow relevant information to be forwarded to them at specified times.
To retrieve the details from the form and add them to the database I followed a tutorial and produced this code
public function saveAction()
{
$title = $this->getRequest()->getPost('title');
$f_name = $this->getRequest()->getPost('f_name');
$l_name = $this->getRequest()->getPost('l_name');
if ( isset($title) && ($title != '') && isset($f_name) && ($f_name != '') && isset($l_name) && ($l_name != '') ) {
$contact = Mage::getModel('prefcentre/prefcentre');
$contact->setData('title', $title);
$contact->setData('f_name', $f_name);
$contact->setData('l_name', $l_name);
$contact->save();
$this->_redirect('prefcentre/index/emailPreferences');
} else {
$this->_redirect('prefcentre/index/signUp');
}
}
The tutorial says to put it into the controller in a saveAction, and that works fine. However from my very limited understanding it would go in to a helper and i'd call the helper from the controller
I placed the above code in my helper and called it from within the saveAction using the following
Mage::helper('module/helpername');//returned blank screen and did not save
I also tried
Mage::helper('module/helpername_function');//returned error
My config has
<helpers>
<prefcentre>
<class>Ps_Prefcentre_Helper</class>
</prefcentre>
</helpers>
1 . Should this code go in a helper, if not where should it go?
2 . How do I call the helper(or the location the code need to go) to utilise the code?
1 . Should this code go in a helper, if not where should it go?
The actual code you posted imo is predestinated to be used within a controller action because it realizes a very specific process flow: Get user data for a specific case -> save if applicable -> redirect.
Secondly, a helper imo never should control route dispatching. It's a helper, not a controller.
I fail to see any use case where putting the method into a helper would give any advantages.
2 . How do I call the helper(or the location the code need to go) to
utilise the code?
Your definition uses <prefcentre> as alias, so if you did setup the helper the Magento standard way and using the file app/code/local/Ps/Prefcentre/Helper/Data.php, than your helper methods are callable like this:
Mage::helper('prefcentre')->myMethodName();

silverstripe permissions - prevent dataobject from being edited

at the moment I´m checking out the canEdit and canDelete Functions of Dataobject. As far as I can see I have to call that functions always manually in the template or other php code... Is there a way to prevent editing/deleting in general for a certain Dataobject? When I saw the canEdit function the first time I expected it to be checked by silverstripe automatically before writing the DataObject.
So I just want ADMINS to be allowed to write this DataObject:
public function canEdit($member = null){
return(
Permission::checkMember($member = Member::currentUser(), 'ADMIN')
);
}
Regards,
Florian
public function canEdit($member){
if (Permission::check('ADMIN')){
return true;
}else{
// do something here if applicable
}
}
Reference Link 1
Reference Link 2
Reference Link 3

Wordpress: Accessing A Plugin's Function From A Theme

I'm trying to add some functionality from a plugin I have made into a Wordpress theme but I am having little joy. The documentation doesn't really help me solve the problem so perhaps someone here can help.
I have a plugin in Wordpress that is activated and working fine. The class for this plugin has a function called generateHtml which I would like to access from a Wordpress Theme. But whatever I try, I cannot seem to access my plugin's code.
Can either give me a summary of what I need to do to get a theme accessing code from a plugin and/or point out there I am going wrong in my code:
Plugin:
<?php
/** Usual comments here **/
if (!class_exists("ImageRotator")) {
class ImageRotator {
private $uploadPath = '';
private $pluginPath = '';
private $options;
function __construct() {
$this->uploadPath = dirname(__file__).'\\uploads\\';
// add_shortcode('imagerotator', array(&$this, 'generateHtml'));
}
// Various functions for plugin
function generateHtml() {
echo '<p>Hello World</p>';
}
}
}
/**
* Create instance of image rotator
*/
$imageRotator = new ImageRotator();
/**
* Create actions & filters for Wordpress
*/
if (isset($imageRotator)) {
// Actions
add_action('admin_menu', array(&$imageRotator, 'createMenu'));
add_action('admin_init', array(&$imageRotator, 'registerSettings'));
add_action('imagerotator_show', array(&$imageRotator, 'generateHtml'));
}
Portion from theme header page:
<?php if (isset($imageRotator)) {
$imageRotator->generateHtml();
} else if (isset($ImageRotator)) {
print_r($ImageRotator);
} else {
echo '<p>Nope!</p>';
}
if (function_exists("imagerotator_show")) {
echo 'Function found';
} else {
echo 'Function NOT found';
}
?>
Currently all I ever see is "Nope" and "Function NOT found". Thanks for any input.
Lee,
For starters, "imagerotator_show" is not a function; it's the name of a type of action. When you use the add_action() function, Wordpress just adds your method to the list of functions/methods to call when a particular action is triggered. Thus your second test will always respond with 'Function NOT found'.
The most likely cause of the first problem is failing to declare the method you want to call as a public method. You're also making the code harder than it needs to be.
The best practice I've seen for declaring methods and registering hooks from a class looks something like this:
if ( ! class_exists( 'Foo' ) ):
class Foo {
function __construct() {
add_action( 'hook_name', array( &$this, 'my_hook_implementation' ) );
}
function my_hook_implementation() {
// does something
}
public function my_special_method() {
// does something else
}
}
if ( class_exists( 'Foo' ) ):
$MyFoo = new Foo();
This allows your class to keep all of its implementation details private. When you need to call my_special_method(), you do it as follows:
$MyFoo->my_special_method();
#andrew since I can't comment I thought I would answer your ancillary question. See:
http://net.tutsplus.com/tutorials/wordpress/create-wordpress-plugins-with-oop-techniques/
Where it is explained that when defining a callback function from an object you have to use the array function. It's basically saying get the function 'my_hook_implementation' from the object $this and use it as the callback parameter to the add action hook. It is because you defined the function within the scope of the object and you have to define the scope in order for PHP to know what function you are talking about. The scope being the object referred to by the variable $this.
You just need to use do_action() function, inside your theme.
If you want the function generateHtml to appears inside your header.php you just need to open the header.php file and paste <?php do_action('imagerotator_show'); ?> where you want and then your function will be called there.