Learning MVC PHP

Kirk

Well-known member
Hi everyone,

So I was wondering should I be learning PHP OOP on top of Zend Framework to develop xenforo add-ons? I know i've seen threads where Xenforo uses some of Zend Framework's features. I just dont want to go all over the place when developing add-ons for XenForo
 
Last edited:
Zend Framework doesn't really mean anything, to be honest.

It's a framework and XenForo only uses a small part of it. Learning it probably isn't going to help you all that much.

And that's the only answer I can give, really. I don't learn from books and other tuition. I'm completely self taught and I learnt by doing and understanding the XenForo code.

I think we have had this conversation before, but basically I recommend getting as far as you can on your own, and asking specific questions about your current issues in the Development forum.

I'm a firm believer that you don't necessarily need to understand something inside out to learn something. It's ok to not understand everything. Just get stuck in and when you hit a wall, ask a question.
 
I agree. I'm completely self taught as well. The XenForo development section is very helpful. I was familiar with OOP before starting on add ons but I had never worked with Zend. I'd stick to reading the development topics on here.

In addition to what Chris said about XenForo not using all of Zend Frameworks classes and functions; There are a lot XenForo classes that aren't apart or extension of Zend such as DataWriters so knowing Zend inside and out won't be all that helpful.
 
I agree. I'm completely self taught as well. The XenForo development section is very helpful. I was familiar with OOP before starting on add ons but I had never worked with Zend. I'd stick to reading the development topics on here.

In addition to what Chris said about XenForo not using all of Zend Frameworks classes and functions; There are a lot XenForo classes that aren't apart or extension of Zend such as DataWriters so knowing Zend inside and out won't be all that helpful.
Thank you very much Daniel.
 
Zend Framework doesn't really mean anything, to be honest.

It's a framework and XenForo only uses a small part of it. Learning it probably isn't going to help you all that much.

And that's the only answer I can give, really. I don't learn from books and other tuition. I'm completely self taught and I learnt by doing and understanding the XenForo code.

I think we have had this conversation before, but basically I recommend getting as far as you can on your own, and asking specific questions about your current issues in the Development forum.

I'm a firm believer that you don't necessarily need to understand something inside out to learn something. It's ok to not understand everything. Just get stuck in and when you hit a wall, ask a question.
Hi,

But would you say xenforo attempts to adopt the Zend framework "model"? If so, then just reading up on zend docs explaining the philosophy of the MVC model should be useful. Right? (I'm new to xenforo but am slowing beginning to understand). :)
 
Think of XenForo as its own framework. Concentrate on learning that (by looking at the code and doing things with the code) rather than learning and understanding a framework that isn't really used in a big way.

Especially as Zend Framework isn't likely to feature in XenForo 2.0 at all. The concepts you learn from XenForo 1.X will be a good basis for learning XenForo 2.X.
 
Think of XenForo as its own framework. Concentrate on learning that (by looking at the code and doing things with the code) rather than learning and understanding a framework that isn't really used in a big way.

Especially as Zend Framework isn't likely to feature in XenForo 2.0 at all. The concepts you learn from XenForo 1.X will be a good basis for learning XenForo 2.X.
And of course looking at your code from the add-ons i've bought from you are quite helpful. Well written :). However lets say we look at other author's code and they have sloppy code. Is there even a proper standard to code for XenForo other than having the correct Folder structure?
 
I felt like I made great progress in understanding xenforo. What I did was read this tutorial by @Fuhrmann, then downloaded and installed @Kier's ajax tutorial add-on, analysed the add-on files then watched his video for the add-on. To make sure I had the basic concepts, I stole all of the add-on code from the tutorial and used it to successfully create my own add-on. Doing that helped me understand the class names and file structure better.

I still have much to learn, but I believe I now have a good basic understanding of the Xenforo MVC paradigm.

At the moment there are two things that elude my understanding, and hope that someone will help give me some greater insight.

1) I still can't figure out the purpose of using Xen tags in my templates. I can't figure out if it's some sort of interface between Html and PHP or ??? In my controller I use PHP to create some variables, but in my template I have to use Xen tags to access the contents of those variables. Why is that, I wonder??? It's a mystery to me.

2) In @Kier's add-on, he creates and uses a javascript file that is physically located in the "JS" sub-directory. Why does he do this and for that matter why is the JS directory even there for?? I can render javascript directly in my template, so why would I include my javascript from a file in the "JS" sub-directory?? Is it for performance, is it a coding style, or is it because it supports javascript functions that can't be done within a template?? This is also a mystery to me.

I hope someone out there can help enlighten me.
 
1) I still can't figure out the purpose of using Xen tags in my templates. I can't figure out if it's some sort of interface between Html and PHP or ??? In my controller I use PHP to create some variables, but in my template I have to use Xen tags to access the contents of those variables. Why is that, I wonder??? It's a mystery to me.

The xen tags are to mix php and html logic. If you just did <span>$test</span>, it'd print literally that. You can wrap $test in {}s and that'll work but what if $test is empty or doesn't exist at all? You need to check it, html doesn't have a way to do this so the xen tags are used:
Code:
<xen:if is="{$test}"><span>{$test}</span></xen:if>
Now the span only exists if $test is defined and not empty. That's just one example.
 
The xen tags are to mix php and html logic. If you just did <span>$test</span>, it'd print literally that. You can wrap $test in {}s and that'll work but what if $test is empty or doesn't exist at all? You need to check it, html doesn't have a way to do this so the xen tags are used:
Code:
<xen:if is="{$test}"><span>{$test}</span></xen:if>
Now the span only exists if $test is defined and not empty. That's just one example.
Thanks very much for your reply. (y)

But couldn't you add some PHP to the template to do the same thing?

Something like:
<!php
echo '<span>' . $test . '</span>'
>
 
Oh... another question I hope someone could answer.

I'm currently using a local copy of xenforo for my dev and testing. To install my add-on, I'll need to put the production site in debug mode for me.

I see there is a way to modify config.php to enable debug mode based on ip address. Buy my address is generated from my ISP by DHCP. So my address is always changing.

Is there a way to turn on debug mode based on UserId? Is so, that would solve my problem.
 
The xen tags are to mix php and html logic. If you just did <span>$test</span>, it'd print literally that. You can wrap $test in {}s and that'll work but what if $test is empty or doesn't exist at all? You need to check it, html doesn't have a way to do this so the xen tags are used:
Code:
<xen:if is="{$test}"><span>{$test}</span></xen:if>
Now the span only exists if $test is defined and not empty. That's just one example.
I tried adding <!php echo 'Hello' !> but that didn't work, so I guess the templates can't parse PHP. But the variable is still a PHP variable, so how does Xenforo access it?

What I am trying to do is get the value of a PHP variable into a javascript variable. The only I can figure so far is put the value somewhere in the HTML, then use javascript and the DOM to access the value. It works, but seems very kludgy. Hoping for a better way.
 
Top Bottom