I'm working on a new website. This website will be a one pager. All my files I already load in through PHP into the main folder. But now I want to edit them and update them through WYSIWYG.
The UPDATE and SELECT are already working. I tested it on a page who stood on its own. All the one-pager files are stored in a folder and within the folder is also the file which loads all the files into it. I call them through a href which ends up giving the file an # in the address bar. There lies the problem. I can't access the #file with the function I wrote because that only can access files without starting a #. Is it possible to access it through my function?
I give the code if the question is too unclear because it's a bit of mess to implement all the files I use for this purpose.
Short recap: Can't access #domain with a PHP function. Is it even possible to access it.
<?php
class Home extends Controller {
protected function frontpage() {
$viewmodel = new HomeModel();
$this->returnView($viewmodel->frontpage(), true);
}
}
?>
this is the returnView from Controller:
protected function returnView($viewmodel, $fullview){
$view = 'views/'. get_class($this). '/' . $this->action. '.php';
if($fullview){
require('views/main.php');
} else {
require($view);
}
}
I'm new with overflow so I couldn't get the function into right place but with protected function frontpage I should access the file frontpage.php. Well it does do that but that's not the right directory because it's only visible throug a href which means the function should have been: protected function #frontpage which isn't possible.
This is actually not possible, as the anchor (#) isn't sent to the server and is handled by the browser itself.
The only possibility is to include some JavaScript magic to your project.
Related
I have a primary controller located in secure/application/modules/gps/controllers that has a constructor that looks like this:
public function __construct()
{
parent::__construct();
$this->load->model('gps_model');
Assets::add_module_js('gps', 'gps.js');
Assets::add_module_css('gps','gps.css');
if($this->input->get('clear') != false){
$this->session->sess_destroy();
}
}
My CSS file that I am trying to include is located in the folder secure/application/modules/gps/assets/css. The code executes fine without warning, but the CSS file does not get included for any methods. Is there a configuration setting the may override the assets directory, or is there some other reason it's not being found/added? (The JS file is not being added either. The bonfire base CSS files (screen.css) IS getting loaded fine.
We found the solution to our particular problem.
The assets/cache directory did not exist. Once the server could write (it must exist and be writeable!) to the [document_root]/bonfire/public/assets/cache directory all was good.
This is not a solution, but I have faced the same problem and found help with the below information.
It'll added in your page but can you just look on ctrl+u source where bonfire will auto rename your file.
For example : In my code I have added id_proof_master.css file like below.
public function __construct()
{
parent::__construct();
$this->auth->restrict($this->permissionView);
$this->load->model('id_proof_master/id_proof_master_model');
$this->lang->load('id_proof_master');
$this->form_validation->set_error_delimiters("<span class='error'>", "</span>");
Template::set_block('sub_nav', 'master/_sub_nav');
Assets::add_module_js('id_proof_master', 'id_proof_master.js');
Assets::add_module_css('id_proof_master', 'id_proof_master.css');
}
And it's working fine but when I have check in source view (ctrl+u) it will show file name like "id_proof_master_master_mod.min.css" so can you just check it out in source; maybe it'll show you with some other name like my file.
I am just wondering, I actually decided to go down a different route.
I create this file A
C:\somefolder\templates\mytemplate\joomlaoverwrites\libraries\joomla\document\html\renderer\head.php
which overwrites a joomla library file:
C:\somefolder\libraries\joomla\document\html\renderer\head.php
I use the overwrite by using
require_once(__DIR__ . '/joomlaoverwrites/libraries/joomla/document/html/renderer/head.php');
in my index.php of my template
This actually works.
What I now want to do is use my file just as a wrapper class, and sneak my changes into it before returning the answer. E.g.:
public function fetchHead($document)
{
$joomlasOriginalHead = callOriginalFunctionFetchHeadFromTheJoomlaImplementation();
//do my changes to joomlas original answer and return that
}
E.g. from that overwrite, I want to call the original file. Is that somehow possible?
There are two pieces to this code:
One that adds documents to an index to be searched, which works fine, and a crawl() function that is a web-crawler that gets the contents of a page, which also works fine.
But, I need to add a document from inside the crawl() function.
When I move the code that adds a document inside the crawl() function, I get a Fatal Error:
Fatal Error: call to member function addDocument() on a non-object.
I am wondering how I can access the member function addDocument() from inside the crawl function?
Right now, I have a working version where the crawl() function returns what it has crawled in the form of a variable and then the addDocument code, outside the crawl() function, also has access to the returned variable and adds the document to the index that way.
But, that only (logically) works when I am crawling one page or a page with no links to follow. As the function only returns when it is done and since it is recursive to follow a page's links, the only content it will return is the content of the last-page.
Where I need the content of each page to be added each as a new document in the index.
Here is the working code, described above, commented as much as I could: http://pastebin.com/5ngcucDp
and here is the non-working code where I try to move the addDocument() inside the crawl() function: http://pastebin.com/mUEwQJTG
If you have a solution that involves how to access the addDocument() function from inside the crawl() function, then please share.
Or if you have a solution that involves modifying the working code so that it returns the contents of each page it crawls instead of the last-page, please share.
If you have any solutions, please share as I am absolutely exhausted and have tried everything I know.
When moving code to a function, you are completely removing its ability to access variables in the same scope. In this case, you probably (not going to go looking through your off-site code) have something like $someObject = new myClass();, then are trying to access $someObject->addDocument() on it from within the function.
You need to pass $someObject as a parameter to the function, or you could use global $someObject inside the function, though it's not as good an idea.
You have specified that:
// The below line is where the error takes place.
$elasticaType->addDocument($document);
Is your error line. Now, PHP is trying to access a class linked to $elasticaType If you have a linked class then use:
$elasticaType = new ClassName();
If not then you should create a class:
class Name {
public function addDocument ($document){
//Add document code
return $somevar;
}
}
$elasticaType = new Name();
$elasticaType->addDocument($document);
I have a problem in CodeIgniter, and that is that when an image is not found on the server, the instance of a controller is created (besides the one that called the view).
I know all this can sound confusing, so this is the code to observe what I'm saying. I did this changes to a clean 2.1.0 CI version:
Add a controller to override the 404 error page, I added this one:
// add application/controllers/Errors.php
Class Errors extends CI_Controller {
public function error_404() {
echo 'error';
}
}
// change routes.php
$route['404_override'] = 'Errors/error_404';
Use a controller that isn’t the default one with an unexisting image, I used this:
// add application/controllers/Foo.php
Class Foo extends CI_Controller {
public function index() {
echo '<img src="doesntexist.png" />';
}
}
I couldn’t figure out another way of debugging it, so I created a log to write the events on CodeIgniter.php:
// add on CodeIgniter.php line 356
$path = 'log.txt'; //Place log where you can find it
$file = fopen($path, 'a');
fwrite($file, "Calling method {$class}/{$method} with request {$_SERVER['REQUEST_URI']}\r\n");
fclose($file);
With this, the log that generates visiting the index function is the following:
Calling method Foo/index with request /test/index.php/Foo
Calling method Errors/error_404 with request /test/index.php/doesntexist.png
Which is the problem I have, an instance of the Error class is created.
that is that when an image is not found on the server, the instance of a controller is created
Not really. What I believe is happening is that, since you're using a relative path for the image (and calling it directly inside a controller, which is wrong because you're ouputting something before headers), your browser attach the image directly to the CI url, thus making this request to the server:
index.php/doesntexist.png
Which is (correctly) interpreted by CI as a request to a controller, which doesn't exists, and therefore it issues the error class.
You could do, in your actual code (I'd put the images in a view, though):
echo '<img src="/doesntexist.png" />'
using an absoluth path, or using the base_url() method from the url helper:
echo '<img src="'.base_url().'doesntexist.png" />
This should tell the server to fetch the right request (/test/doesntexist.png) and won't trigger that error.
I am learning how to use codeIgniter as my php framework. I am reading through the documentation and watching the intro video and just generally following along with the first tutorial, but it's not working for me.
I have created a controller called "test.php" and a view called "test_view". The controller for this class is exactly like "welcome.php" and the view file just has some static html. However, when I go to index.php/test I get a 404 error.
I have also tried manipulating the original welcome files so that instead of calling a view it just echos "testing", yet I still see the original welcome message! I've tried clearing my browsing cash and refreshing, but to no avail.
Any suggestions? Thanks.
Edit: Here's the code for controllers/test.php
<?php
class Test extends Controller {
//Just trying to get it to echo test
public function index()
{
echo "test";
//$this->load->view('test_view');
}
}
?>
Try looking at this page in the documentation - this might solve your problem.
This basically means you should try typing index.php?/test/ instead (notice the question-mark).
First of all, check the above link. Might be useful.
If not, then...
Try changing the default controller in the config file ('routes.php') to something else (probably, to 'test'), then try loading index.php. Just to test whether the whole system works (or not).
Check whether mod_rewrite is loaded (in your server .conf-file, if you're using Apache).
Try using the latest build of the framework. AFAIK, the name of the controller class for now is "CI_Controller".
Finally, try removing the word 'public' before the declaration of the function. AFAIR, CI enable you to make private functions in controllers just by using prefix (which is set in the config file) at the beginning of the name of the function (thus making all the other functions public).
But most certainly the problem is with the mod_rewrite. If not, try debugging with die('Page found'); instead of echo - this will allow you to track possible redirects on the page.