Jump to content

Friendly Names Not Saved...


Recommended Posts

A while back I added like 20 or 30 rows to a table via a for loop. I just looked in the db and noticed SOME of them don't have their friendly titles stored!

They're all in the same table, all were created at the same time via the same for loop, all of them have their titles stored, yet around 5 or 10 do not have the friendly version saved! What in the world??? And all of the titles were generated automatically such as dummy1, dummy2, dummy3, etc... so I can think of no reason at all why this would be happening.

Link to comment
Share on other sites

I think the problem here is it never added friendly names to the db at all on creation...

So when I go to pages that ist these items, apparently "then" it saves them at the time it creates their links.

I just assumed for content items, it would automatically store the friendly name during create(). I guess this is not the case? Does anyone set them manually on creation or everyone just has it do it when it creates a url and doesn't already have the friendly name?

For a node, I saw in an IPS app there is a getter that checks for a friendly name and, if one doesn't exist, it gets the custom lang bit and saves the friendly name to the db. However, I am talking about content items, so obviously the name isn't translatable. Why is create() not automatically storing a friendly name? That would be easy, since we are using the map to show what our title column is.

Link to comment
Share on other sites

In my content item:

	/**
	 * Set the title
	 *
	 * @param	string	$title	Title
	 * @return	void
	 */
	public function set_title( $title )
	{
		$this->_data['title'] = $title;
		$this->_data['title_seo'] = \IPS\Http\Url\Friendly::seoTitle( $title );
	}

	/**
	 * Get SEO name
	 *
	 * @return	string
	 */
	public function get_title_seo()
	{
		if( !$this->_data['title_seo'] )
		{
			$this->title_seo	= \IPS\Http\Url\Friendly::seoTitle( $this->title );
			$this->save();
		}

		return $this->_data['title_seo'] ?: \IPS\Http\Url\Friendly::seoTitle( $this->title );
	}

	/**
	 * @brief	Cached URLs
	 */
	protected $_url	= array();

	/**
	 * @brief	URL Base
	 */
	public static $urlBase = 'app=raffles&module=raffles&controller=view&id=';

	/**
	 * @brief	URL Base
	 */
	public static $urlTemplate = 'raffles_raffle';
	
	/**
	 * @brief	SEO Title Column
	 */
	public static $seoTitleColumn = 'title_seo';

 

If you have this, it will do the "magic".

Link to comment
Share on other sites

17 minutes ago, Adriano Faria said:

In my content item:


	/**
	 * Set the title
	 *
	 * @param	string	$title	Title
	 * @return	void
	 */
	public function set_title( $title )
	{
		$this->_data['title'] = $title;
		$this->_data['title_seo'] = \IPS\Http\Url\Friendly::seoTitle( $title );
	}

	/**
	 * Get SEO name
	 *
	 * @return	string
	 */
	public function get_title_seo()
	{
		if( !$this->_data['title_seo'] )
		{
			$this->title_seo	= \IPS\Http\Url\Friendly::seoTitle( $this->title );
			$this->save();
		}

		return $this->_data['title_seo'] ?: \IPS\Http\Url\Friendly::seoTitle( $this->title );
	}

	/**
	 * @brief	Cached URLs
	 */
	protected $_url	= array();

	/**
	 * @brief	URL Base
	 */
	public static $urlBase = 'app=raffles&module=raffles&controller=view&id=';

	/**
	 * @brief	URL Base
	 */
	public static $urlTemplate = 'raffles_raffle';
	
	/**
	 * @brief	SEO Title Column
	 */
	public static $seoTitleColumn = 'title_seo';

 

If you have this, it will do the "magic".

I didn't do the setter or getter. In my node model I did a similar getter (trasnlatable, though, obviously).

Anyway, thanks! I see it in Topic.php now. Somehow I never noticed it before when I looked through it. So that takes care of that issue. ?

Now if only I can figure out some weird behavior in my database where there are a few rows that I have no idea how they got there. I think I may be accidentally creating some duplicate rows somehow... Oh well, will look closer on that later.

I've got a lot of bugs fixed lately and nothing is going horribly, at least.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...