Welcome Guest, Not a member yet? Register   Sign In
Advanced Question: How to detect if and on what page a function is used?
#1

[eluser]Gwarrior[/eluser]
I know this is extremely confusing, but I've been working on a Codeigniter Light CMS system and after seeing Perch CMS, I would like to use one of it's features.

Using Perch, a user simply adds a php function to their code like so:

Code:
<h1>Static Content</h1>
<div class="content">
&lt;?php perch_content('Main Content'); ?&gt;
</div>

This causes a [NEW] message to pop up in the admin panel saying something like

Quote:New: Main Content on Page: Homepage

If I confused you, I apologize. A quick view of the Homepage Video will explain how the system works better than I can.

I can't wrap my head around how I could do something like this, let alone do it in a CI environment.

Any ideas? Thanks!
#2

[eluser]bigtony[/eluser]
You would need the following:

1. An admin area (controlled by username/password) which then allows you to define the two fields 'code' and 'value' (e.g. 'Main Content' and 'This is my main content text...'. You would store this in a database table keyed by 'code'.

2. Create a CI helper containing your version of the function 'perch_content', the function defined to receive 'code' as a parameter. The function retrieves the entry from the database and returns it to the caller.

3. Insert the call to 'perch_content' in your view, except preceed it with 'echo':
Code:
&lt;?php echo perch_content('Main Content'); ?&gt;
#3

[eluser]Gwarrior[/eluser]
Thanks for replying.

I think you're on track and exactly where I went with this, but Perch actually requires that you put the function into the file then load it once, which must execute some type of function that logs the title and provided parameter into a database after checking the provided parameter against data already in the db to determine if it needs to create a new content option and even take this info.

So my idea is to have a helper like you said, retrieving a parameter: (in a view file)
Code:
&lt;?php perch_content('Main Content'); ?&gt;

and that function would run a database query to pull out the filename without the extension and insert it into the database, along with the words: Main Content.

And then on the admin panel side, we would have a script that displays the contents of the database, then lets you select one and carry on to a 'Create Content' section where you can add the actual text with some sort of WYSIWYG editor and use additional fields. Then the perch_content() function could accept additional parameters for these additional fields to narrow it down.

Example:
Code:
<h1>&lt;?php perch_content('Main Content', 'title'); ?&gt;</h1>
<div id="content">
&lt;?php perch_content('Main Content', 'body'); ?&gt;
</div>

Therefore leaving you with a database table with the following columns:

id (in this case, 0 for the first)
call_tag (in this case, Main Content)
new (a bool value, which will change upon the first update to FALSE)
title (for the title | optional)
body (for the main text body | required)
extra_1 (for extra field | optional)
extra_2 (for 2nd extra field | optional)
extra_3 (for 3rd extra field | optional)
extra_4 (for 4th extra field | optional)

Does this seem like the correct approach?

Thanks in advance for any more comments!
#4

[eluser]bigtony[/eluser]
[quote author="Gwarrior" date="1253889434"]Does this seem like the correct approach?[/quote]
Bear in mind that Perch wasn't build with CI so we need a bit of adaptation. I would simplify it along the lines I gave earlier, where perch_content() only takes a single parameter. Your database table would only need to store a 'code' (e.g. 'Main Content') as the key amd 'content' as the value (which would come from a wysiwyg editor).

The helper would look somethink like this:
Code:
function perch_content($code) {
   // Load data from db table
   $row = ...code to retrieve data...

   // Return the 'value' column from the table
   return $row->value;
}

Then in your view, just remember to use 'echo' before the function call so it displays the returned value.

If you get this simple version working first you could then enhance more along the lines of Perch if you wanted, but I think the simple version would go a long way!




Theme © iAndrew 2016 - Forum software by © MyBB